From 9b971fbd3defc20ffa6aae18a84d0d13831f4cd0 Mon Sep 17 00:00:00 2001 From: Alexander Lisachenko Date: Thu, 14 May 2026 01:58:12 +0300 Subject: [PATCH] fix: replace deprecated add() with addCommands() in bin/aspect Symfony Console 8.x removed the Application::add() method. Switch to the addCommands() API and add a functional test that executes the actual bin/aspect CLI to verify all commands are properly registered. Closes #575 Co-Authored-By: Claude Opus 4.7 (1M context) --- bin/aspect | 10 +++--- tests/Console/ApplicationTest.php | 60 +++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 tests/Console/ApplicationTest.php diff --git a/bin/aspect b/bin/aspect index ab31ba13..63859df5 100755 --- a/bin/aspect +++ b/bin/aspect @@ -40,8 +40,10 @@ if (!class_exists(Application::class)) { } $app = new Application('Go! AOP', InstalledVersions::getVersion('goaop/framework')); -$app->add(new CacheWarmupCommand()); -$app->add(new DebugAspectCommand()); -$app->add(new DebugAdvisorCommand()); -$app->add(new DebugWeavingCommand()); +$app->addCommands([ + new CacheWarmupCommand(), + new DebugAspectCommand(), + new DebugAdvisorCommand(), + new DebugWeavingCommand(), +]); $app->run(); diff --git a/tests/Console/ApplicationTest.php b/tests/Console/ApplicationTest.php new file mode 100644 index 00000000..f3c3cfd6 --- /dev/null +++ b/tests/Console/ApplicationTest.php @@ -0,0 +1,60 @@ + + * + * This source file is subject to the license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Go\Console; + +use PHPUnit\Framework\TestCase; +use Symfony\Component\Process\PhpExecutableFinder; +use Symfony\Component\Process\Process; + +class ApplicationTest extends TestCase +{ + private string $console; + + public function setUp(): void + { + $this->console = __DIR__ . '/../../bin/aspect'; + } + + public function testListCommandShowsAllRegisteredCommands(): void + { + $process = $this->runConsoleCommand('list', ['--no-ansi']); + + $this->assertTrue($process->isSuccessful(), $process->getErrorOutput() ?: $process->getOutput()); + $this->assertStringContainsString('cache:warmup:aop', $process->getOutput()); + $this->assertStringContainsString('debug:aspect', $process->getOutput()); + $this->assertStringContainsString('debug:advisor', $process->getOutput()); + $this->assertStringContainsString('debug:weaving', $process->getOutput()); + } + + public function testVersionOptionShowsApplicationVersion(): void + { + $process = $this->runConsoleCommand('list', ['--version']); + + $this->assertTrue($process->isSuccessful(), $process->getErrorOutput() ?: $process->getOutput()); + $this->assertStringContainsString('Go! AOP', $process->getOutput()); + } + + private function runConsoleCommand(string $command, array $args = []): Process + { + $phpExecutable = (new PhpExecutableFinder())->find(); + $commandLine = array_merge( + [$phpExecutable, $this->console, $command], + $args + ); + + $process = new Process($commandLine); + $process->run(); + + return $process; + } +}