From c8fa36adf9261d60cb5668204bbfe33fe60c1898 Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Tue, 15 Sep 2026 20:06:58 +0800 Subject: [PATCH] test: keep CommandsTest out of app/Commands so parallel runs do not race --- tests/system/CLI/CommandsTest.php | 35 +++++++++++++------------------ 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/tests/system/CLI/CommandsTest.php b/tests/system/CLI/CommandsTest.php index 34bb0601da65..cd284960909d 100644 --- a/tests/system/CLI/CommandsTest.php +++ b/tests/system/CLI/CommandsTest.php @@ -13,7 +13,9 @@ namespace CodeIgniter\CLI; +use App\Commands\ListCommands as AppListCommands; use CodeIgniter\Autoloader\FileLocatorInterface; +use CodeIgniter\Commands\ListCommands; use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\StreamFilterTrait; use Config\Services; @@ -42,22 +44,6 @@ protected function resetAll(): void CLI::reset(); } - private function copyAppListCommands(): void - { - if (! is_dir(APPPATH . 'Commands')) { - mkdir(APPPATH . 'Commands'); - } - - copy(SUPPORTPATH . '_command/ListCommands.php', APPPATH . 'Commands/ListCommands.php'); - } - - private function deleteAppListCommands(): void - { - if (is_file(APPPATH . 'Commands/ListCommands.php')) { - unlink(APPPATH . 'Commands/ListCommands.php'); - } - } - public function testRunOnUnknownCommand(): void { $commands = new Commands(); @@ -166,13 +152,22 @@ public function testDiscoverCommandsWithNoFiles(): void public function testDiscoveredCommandsCanBeOverridden(): void { - $this->copyAppListCommands(); + // The fixture sits outside any PSR-4 root, so the autoloader cannot load it. + require_once SUPPORTPATH . '_command/ListCommands.php'; + + $files = [ + SUPPORTPATH . '_command/ListCommands.php' => AppListCommands::class, + SYSTEMPATH . 'Commands/ListCommands.php' => ListCommands::class, + ]; + + $locator = $this->createMock(FileLocatorInterface::class); + $locator->method('listFiles')->with('Commands/')->willReturn(array_keys($files)); + $locator->method('findQualifiedNameFromPath')->willReturnCallback(static fn (string $file): string => $files[$file]); + Services::injectMock('locator', $locator); - command('list'); + (new Commands())->run('list', []); $this->assertStringContainsString('This is App\Commands\ListCommands', $this->getStreamFilterBuffer()); $this->assertStringNotContainsString('Displays basic usage information.', $this->getStreamFilterBuffer()); - - $this->deleteAppListCommands(); } }