diff --git a/src/Application.php b/src/Application.php index 7a0932df..93a443d0 100644 --- a/src/Application.php +++ b/src/Application.php @@ -35,7 +35,16 @@ public function run(InputInterface $input): int false === getenv('SYMFONY_VERSION') ? 'master' : getenv('SYMFONY_VERSION') ); $this->application->getDefinition()->addOption($inputOption); - $this->application->add(new BuildDocsCommand($this->buildConfig)); + + $command = new BuildDocsCommand($this->buildConfig); + + // Application::add() was deprecated in Symfony 7.4 and removed in 8.0, + // in favor of Application::addCommand(), introduced in 7.4 + if (method_exists($this->application, 'addCommand')) { + $this->application->addCommand($command); + } else { + $this->application->add($command); + } return $this->application->run($input); } diff --git a/tests/ApplicationTest.php b/tests/ApplicationTest.php new file mode 100644 index 00000000..e7540c3f --- /dev/null +++ b/tests/ApplicationTest.php @@ -0,0 +1,33 @@ + + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace SymfonyDocsBuilder\Tests; + +use PHPUnit\Framework\TestCase; +use Symfony\Component\Process\Process; + +/** + * The rest of the test suite drives the command through CommandTester, so it + * never runs the binary itself. This makes sure the binary at least boots. + */ +class ApplicationTest extends TestCase +{ + public function testTheBinaryRegistersTheBuildDocsCommand() + { + $process = new Process([\PHP_BINARY, __DIR__.'/../bin/docs-builder', 'list', '--no-ansi']); + $process->run(); + + $this->assertSame( + 0, + $process->getExitCode(), + sprintf("The binary failed to run:\n%s", $process->getErrorOutput()) + ); + $this->assertStringContainsString('build:docs', $process->getOutput()); + } +}