diff --git a/UPGRADE-7.3.md b/UPGRADE-7.3.md index 83deba577968d..afd6b81ded8fd 100644 --- a/UPGRADE-7.3.md +++ b/UPGRADE-7.3.md @@ -16,7 +16,7 @@ AssetMapper Console ------- - * Omitting parameter types in callables configured via `Command::setCode()` method is deprecated + * Omitting parameter types or returning a non-integer value from a `\Closure` set via `Command::setCode()` method is deprecated Before: @@ -32,8 +32,10 @@ Console use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; - $command->setCode(function (InputInterface $input, OutputInterface $output) { + $command->setCode(function (InputInterface $input, OutputInterface $output): int { // ... + + return 0; }); ``` diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php index 9afb5a2fd85f6..0b92a813c2d27 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php @@ -135,7 +135,11 @@ public function testRunOnlyWarnsOnUnregistrableCommand() $kernel ->method('getBundles') ->willReturn([$this->createBundleMock( - [(new Command('fine'))->setCode(function (InputInterface $input, OutputInterface $output) { $output->write('fine'); })] + [(new Command('fine'))->setCode(function (InputInterface $input, OutputInterface $output): int { + $output->write('fine'); + + return 0; + })] )]); $kernel ->method('getContainer') @@ -163,7 +167,11 @@ public function testRegistrationErrorsAreDisplayedOnCommandNotFound() $kernel ->method('getBundles') ->willReturn([$this->createBundleMock( - [(new Command(null))->setCode(function (InputInterface $input, OutputInterface $output) { $output->write('fine'); })] + [(new Command(null))->setCode(function (InputInterface $input, OutputInterface $output): int { + $output->write('fine'); + + return 0; + })] )]); $kernel ->method('getContainer') @@ -193,7 +201,11 @@ public function testRunOnlyWarnsOnUnregistrableCommandAtTheEnd() $kernel ->method('getBundles') ->willReturn([$this->createBundleMock( - [(new Command('fine'))->setCode(function (InputInterface $input, OutputInterface $output) { $output->write('fine'); })] + [(new Command('fine'))->setCode(function (InputInterface $input, OutputInterface $output): int { + $output->write('fine'); + + return 0; + })] )]); $kernel ->method('getContainer') diff --git a/src/Symfony/Component/Console/CHANGELOG.md b/src/Symfony/Component/Console/CHANGELOG.md index d0ee13c444eb8..6497def0f43bf 100644 --- a/src/Symfony/Component/Console/CHANGELOG.md +++ b/src/Symfony/Component/Console/CHANGELOG.md @@ -12,6 +12,7 @@ CHANGELOG * Deprecate methods `Command::getDefaultName()` and `Command::getDefaultDescription()` in favor of the `#[AsCommand]` attribute * Add support for Markdown format in `Table` * Add support for `LockableTrait` in invokable commands + * Deprecate returning a non-integer value from a `\Closure` function set via `Command::setCode()` 7.2 --- diff --git a/src/Symfony/Component/Console/Command/Command.php b/src/Symfony/Component/Console/Command/Command.php index 5e30eb5fa8390..f79475d56be73 100644 --- a/src/Symfony/Component/Console/Command/Command.php +++ b/src/Symfony/Component/Console/Command/Command.php @@ -347,7 +347,7 @@ public function complete(CompletionInput $input, CompletionSuggestions $suggesti */ public function setCode(callable $code): static { - $this->code = new InvokableCommand($this, $code, triggerDeprecations: true); + $this->code = new InvokableCommand($this, $code); return $this; } diff --git a/src/Symfony/Component/Console/Command/InvokableCommand.php b/src/Symfony/Component/Console/Command/InvokableCommand.php index 2b3c41501111f..329d8b253cfb8 100644 --- a/src/Symfony/Component/Console/Command/InvokableCommand.php +++ b/src/Symfony/Component/Console/Command/InvokableCommand.php @@ -32,11 +32,11 @@ class InvokableCommand { private readonly \Closure $code; private readonly \ReflectionFunction $reflection; + private bool $triggerDeprecations = false; public function __construct( private readonly Command $command, callable $code, - private readonly bool $triggerDeprecations = false, ) { $this->code = $this->getClosure($code); $this->reflection = new \ReflectionFunction($this->code); @@ -49,17 +49,17 @@ public function __invoke(InputInterface $input, OutputInterface $output): int { $statusCode = ($this->code)(...$this->getParameters($input, $output)); - if (null !== $statusCode && !\is_int($statusCode)) { + if (!\is_int($statusCode)) { if ($this->triggerDeprecations) { trigger_deprecation('symfony/console', '7.3', \sprintf('Returning a non-integer value from the command "%s" is deprecated and will throw an exception in Symfony 8.0.', $this->command->getName())); return 0; } - throw new LogicException(\sprintf('The command "%s" must return either void or an integer value in the "%s" method, but "%s" was returned.', $this->command->getName(), $this->reflection->getName(), get_debug_type($statusCode))); + throw new \TypeError(\sprintf('The command "%s" must return an integer value in the "%s" method, but "%s" was returned.', $this->command->getName(), $this->reflection->getName(), get_debug_type($statusCode))); } - return $statusCode ?? 0; + return $statusCode; } /** @@ -85,6 +85,8 @@ private function getClosure(callable $code): \Closure return $code(...); } + $this->triggerDeprecations = true; + if (null !== (new \ReflectionFunction($code))->getClosureThis()) { return $code; } diff --git a/src/Symfony/Component/Console/Tests/ApplicationTest.php b/src/Symfony/Component/Console/Tests/ApplicationTest.php index 835195743af74..c5c796517c17a 100644 --- a/src/Symfony/Component/Console/Tests/ApplicationTest.php +++ b/src/Symfony/Component/Console/Tests/ApplicationTest.php @@ -196,8 +196,10 @@ public function testRegister() public function testRegisterAmbiguous() { - $code = function (InputInterface $input, OutputInterface $output) { + $code = function (InputInterface $input, OutputInterface $output): int { $output->writeln('It works!'); + + return 0; }; $application = new Application(); @@ -1275,7 +1277,9 @@ public function testAddingOptionWithDuplicateShortcut() ->register('foo') ->setAliases(['f']) ->setDefinition([new InputOption('survey', 'e', InputOption::VALUE_REQUIRED, 'My option with a shortcut.')]) - ->setCode(function (InputInterface $input, OutputInterface $output) {}) + ->setCode(function (InputInterface $input, OutputInterface $output): int { + return 0; + }) ; $input = new ArrayInput(['command' => 'foo']); @@ -1298,7 +1302,9 @@ public function testAddingAlreadySetDefinitionElementData($def) $application ->register('foo') ->setDefinition([$def]) - ->setCode(function (InputInterface $input, OutputInterface $output) {}) + ->setCode(function (InputInterface $input, OutputInterface $output): int { + return 0; + }) ; $input = new ArrayInput(['command' => 'foo']); @@ -1435,8 +1441,10 @@ public function testRunWithDispatcher() $application->setAutoExit(false); $application->setDispatcher($this->getDispatcher()); - $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) { + $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output): int { $output->write('foo.'); + + return 0; }); $tester = new ApplicationTester($application); @@ -1491,8 +1499,10 @@ public function testRunDispatchesAllEventsWithExceptionInListener() $application->setDispatcher($dispatcher); $application->setAutoExit(false); - $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) { + $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output): int { $output->write('foo.'); + + return 0; }); $tester = new ApplicationTester($application); @@ -1559,8 +1569,10 @@ public function testRunAllowsErrorListenersToSilenceTheException() $application->setDispatcher($dispatcher); $application->setAutoExit(false); - $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) { + $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output): int { $output->write('foo.'); + + return 0; }); $tester = new ApplicationTester($application); @@ -1671,8 +1683,10 @@ public function testRunWithDispatcherSkippingCommand() $application->setDispatcher($this->getDispatcher(true)); $application->setAutoExit(false); - $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) { + $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output): int { $output->write('foo.'); + + return 0; }); $tester = new ApplicationTester($application); @@ -1698,8 +1712,10 @@ public function testRunWithDispatcherAccessingInputOptions() $application->setDispatcher($dispatcher); $application->setAutoExit(false); - $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) { + $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output): int { $output->write('foo.'); + + return 0; }); $tester = new ApplicationTester($application); @@ -1728,8 +1744,10 @@ public function testRunWithDispatcherAddingInputOptions() $application->setDispatcher($dispatcher); $application->setAutoExit(false); - $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) { + $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output): int { $output->write('foo.'); + + return 0; }); $tester = new ApplicationTester($application); @@ -1858,12 +1876,12 @@ public function testFindAlternativesDoesNotLoadSameNamespaceCommandsOnExactMatch 'foo:bar' => function () use (&$loaded) { $loaded['foo:bar'] = true; - return (new Command('foo:bar'))->setCode(function () {}); + return (new Command('foo:bar'))->setCode(function (): int { return 0; }); }, 'foo' => function () use (&$loaded) { $loaded['foo'] = true; - return (new Command('foo'))->setCode(function () {}); + return (new Command('foo'))->setCode(function (): int { return 0; }); }, ])); @@ -1934,8 +1952,10 @@ public function testThrowingErrorListener() $application->setAutoExit(false); $application->setCatchExceptions(false); - $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) { + $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output): int { $output->write('foo.'); + + return 0; }); $tester = new ApplicationTester($application); diff --git a/src/Symfony/Component/Console/Tests/Command/CommandTest.php b/src/Symfony/Component/Console/Tests/Command/CommandTest.php index e417b0656e9d9..64d32b2cb6e76 100644 --- a/src/Symfony/Component/Console/Tests/Command/CommandTest.php +++ b/src/Symfony/Component/Console/Tests/Command/CommandTest.php @@ -18,6 +18,7 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Exception\InvalidOptionException; use Symfony\Component\Console\Helper\FormatterHelper; +use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputInterface; @@ -350,8 +351,10 @@ public function testRunWithProcessTitle() public function testSetCode() { $command = new \TestCommand(); - $ret = $command->setCode(function (InputInterface $input, OutputInterface $output) { + $ret = $command->setCode(function (InputInterface $input, OutputInterface $output): int { $output->writeln('from the code...'); + + return 0; }); $this->assertEquals($command, $ret, '->setCode() implements a fluent interface'); $tester = new CommandTester($command); @@ -396,8 +399,10 @@ public function testSetCodeWithStaticClosure() private static function createClosure() { - return function (InputInterface $input, OutputInterface $output) { + return function (InputInterface $input, OutputInterface $output): int { $output->writeln(isset($this) ? 'bound' : 'not bound'); + + return 0; }; } @@ -411,16 +416,20 @@ public function testSetCodeWithNonClosureCallable() $this->assertEquals('interact called'.\PHP_EOL.'from the code...'.\PHP_EOL, $tester->getDisplay()); } - public function callableMethodCommand(InputInterface $input, OutputInterface $output) + public function callableMethodCommand(InputInterface $input, OutputInterface $output): int { $output->writeln('from the code...'); + + return 0; } public function testSetCodeWithStaticAnonymousFunction() { $command = new \TestCommand(); - $command->setCode(static function (InputInterface $input, OutputInterface $output) { + $command->setCode(static function (InputInterface $input, OutputInterface $output): int { $output->writeln(isset($this) ? 'bound' : 'not bound'); + + return 0; }); $tester = new CommandTester($command); $tester->execute([]); @@ -495,14 +504,28 @@ public function testDeprecatedMethods() new FooCommand(); } + + /** + * @group legacy + */ + public function testDeprecatedNonIntegerReturnTypeFromClosureCode() + { + $this->expectDeprecation('Since symfony/console 7.3: Returning a non-integer value from the command "foo" is deprecated and will throw an exception in Symfony 8.0.'); + + $command = new Command('foo'); + $command->setCode(function () {}); + $command->run(new ArrayInput([]), new NullOutput()); + } } // In order to get an unbound closure, we should create it outside a class // scope. function createClosure() { - return function (InputInterface $input, OutputInterface $output) { + return function (InputInterface $input, OutputInterface $output): int { $output->writeln($this instanceof Command ? 'bound to the command' : 'not bound to the command'); + + return 0; }; } diff --git a/src/Symfony/Component/Console/Tests/Command/InvokableCommandTest.php b/src/Symfony/Component/Console/Tests/Command/InvokableCommandTest.php index 3633c865971d5..b0a337fb0a64b 100644 --- a/src/Symfony/Component/Console/Tests/Command/InvokableCommandTest.php +++ b/src/Symfony/Component/Console/Tests/Command/InvokableCommandTest.php @@ -34,7 +34,9 @@ public function testCommandInputArgumentDefinition() #[Argument] string $lastName = '', #[Argument(description: 'Short argument description')] string $bio = '', #[Argument(suggestedValues: [self::class, 'getSuggestedRoles'])] array $roles = ['ROLE_USER'], - ) {}); + ): int { + return 0; + }); $nameInputArgument = $command->getDefinition()->getArgument('first-name'); self::assertSame('first-name', $nameInputArgument->getName()); @@ -75,7 +77,9 @@ public function testCommandInputOptionDefinition() #[Option(shortcut: 'v')] bool $verbose = false, #[Option(description: 'User groups')] array $groups = [], #[Option(suggestedValues: [self::class, 'getSuggestedRoles'])] array $roles = ['ROLE_USER'], - ) {}); + ): int { + return 0; + }); $timeoutInputOption = $command->getDefinition()->getOption('idle'); self::assertSame('idle', $timeoutInputOption->getName()); @@ -138,6 +142,19 @@ public function testInvalidOptionType() $command->getDefinition(); } + public function testInvalidReturnType() + { + $command = new Command('foo'); + $command->setCode(new class { + public function __invoke() {} + }); + + $this->expectException(\TypeError::class); + $this->expectExceptionMessage('The command "foo" must return an integer value in the "__invoke" method, but "null" was returned.'); + + $command->run(new ArrayInput([]), new NullOutput()); + } + /** * @dataProvider provideInputArguments */ @@ -149,11 +166,13 @@ public function testInputArguments(array $parameters, array $expected) #[Argument] ?string $b, #[Argument] string $c = '', #[Argument] array $d = [], - ) use ($expected) { + ) use ($expected): int { $this->assertSame($expected[0], $a); $this->assertSame($expected[1], $b); $this->assertSame($expected[2], $c); $this->assertSame($expected[3], $d); + + return 0; }); $command->run(new ArrayInput($parameters), new NullOutput()); @@ -176,10 +195,12 @@ public function testBinaryInputOptions(array $parameters, array $expected) #[Option] bool $a = true, #[Option] bool $b = false, #[Option] ?bool $c = null, - ) use ($expected) { + ) use ($expected): int { $this->assertSame($expected[0], $a); $this->assertSame($expected[1], $b); $this->assertSame($expected[2], $c); + + return 0; }); $command->run(new ArrayInput($parameters), new NullOutput()); @@ -202,10 +223,12 @@ public function testNonBinaryInputOptions(array $parameters, array $expected) #[Option] ?string $a = null, #[Option] ?string $b = 'b', #[Option] ?array $c = [], - ) use ($expected) { + ) use ($expected): int { $this->assertSame($expected[0], $a); $this->assertSame($expected[1], $b); $this->assertSame($expected[2], $c); + + return 0; }); $command->run(new ArrayInput($parameters), new NullOutput()); diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_0.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_0.php index 8fe7c07712888..86095576c52c5 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_0.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_0.php @@ -5,7 +5,9 @@ use Symfony\Component\Console\Style\SymfonyStyle; //Ensure has single blank line at start when using block element -return function (InputInterface $input, OutputInterface $output) { +return function (InputInterface $input, OutputInterface $output): int { $output = new SymfonyStyle($input, $output); $output->caution('Lorem ipsum dolor sit amet'); + + return 0; }; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_1.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_1.php index e5c700d60eb56..c72a3b3908338 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_1.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_1.php @@ -5,9 +5,11 @@ use Symfony\Component\Console\Style\SymfonyStyle; //Ensure has single blank line between titles and blocks -return function (InputInterface $input, OutputInterface $output) { +return function (InputInterface $input, OutputInterface $output): int { $output = new SymfonyStyle($input, $output); $output->title('Title'); $output->warning('Lorem ipsum dolor sit amet'); $output->title('Title'); + + return 0; }; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_10.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_10.php index 3111873ddde6c..c9bc1e30a0ec9 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_10.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_10.php @@ -5,7 +5,7 @@ use Symfony\Component\Console\Style\SymfonyStyle; //Ensure that all lines are aligned to the begin of the first line in a very long line block -return function (InputInterface $input, OutputInterface $output) { +return function (InputInterface $input, OutputInterface $output): int { $output = new SymfonyStyle($input, $output); $output->block( 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum', @@ -14,4 +14,6 @@ 'X ', true ); + + return 0; }; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_11.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_11.php index 3ed897def42ce..838b66707b9b5 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_11.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_11.php @@ -5,8 +5,10 @@ use Symfony\Component\Console\Style\SymfonyStyle; // ensure long words are properly wrapped in blocks -return function (InputInterface $input, OutputInterface $output) { +return function (InputInterface $input, OutputInterface $output): int { $word = 'Lopadotemachoselachogaleokranioleipsanodrimhypotrimmatosilphioparaomelitokatakechymenokichlepikossyphophattoperisteralektryonoptekephalliokigklopeleiolagoiosiraiobaphetraganopterygon'; $sfStyle = new SymfonyStyle($input, $output); $sfStyle->block($word, 'CUSTOM', 'fg=white;bg=blue', ' § ', false); + + return 0; }; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_12.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_12.php index 8c458ae764dc3..24d64df8d9f62 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_12.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_12.php @@ -5,9 +5,11 @@ use Symfony\Component\Console\Style\SymfonyStyle; // ensure that all lines are aligned to the begin of the first one and start with '//' in a very long line comment -return function (InputInterface $input, OutputInterface $output) { +return function (InputInterface $input, OutputInterface $output): int { $output = new SymfonyStyle($input, $output); $output->comment( 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum' ); + + return 0; }; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_13.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_13.php index 9bcc68f69e2c5..4d079977046b0 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_13.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_13.php @@ -5,10 +5,12 @@ use Symfony\Component\Console\Style\SymfonyStyle; // ensure that nested tags have no effect on the color of the '//' prefix -return function (InputInterface $input, OutputInterface $output) { +return function (InputInterface $input, OutputInterface $output): int { $output->setDecorated(true); $output = new SymfonyStyle($input, $output); $output->comment( 'Árvíztűrőtükörfúrógép 🎼 Lorem ipsum dolor sit 💕 amet, consectetur adipisicing elit, sed do eiusmod tempor incididu labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum' ); + + return 0; }; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_14.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_14.php index a893a48bf248f..b079e4c5df11c 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_14.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_14.php @@ -5,7 +5,7 @@ use Symfony\Component\Console\Style\SymfonyStyle; // ensure that block() behaves properly with a prefix and without type -return function (InputInterface $input, OutputInterface $output) { +return function (InputInterface $input, OutputInterface $output): int { $output = new SymfonyStyle($input, $output); $output->block( 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum', @@ -14,4 +14,6 @@ '$ ', true ); + + return 0; }; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_15.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_15.php index 68402cd408a2d..664a1938b51ab 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_15.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_15.php @@ -5,10 +5,12 @@ use Symfony\Component\Console\Style\SymfonyStyle; // ensure that block() behaves properly with a type and without prefix -return function (InputInterface $input, OutputInterface $output) { +return function (InputInterface $input, OutputInterface $output): int { $output = new SymfonyStyle($input, $output); $output->block( 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum', 'TEST' ); + + return 0; }; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_16.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_16.php index 66e8179638821..2b7bba0595ef6 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_16.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_16.php @@ -5,11 +5,13 @@ use Symfony\Component\Console\Style\SymfonyStyle; // ensure that block() output is properly formatted (even padding lines) -return function (InputInterface $input, OutputInterface $output) { +return function (InputInterface $input, OutputInterface $output): int { $output->setDecorated(true); $output = new SymfonyStyle($input, $output); $output->success( 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum', 'TEST' ); + + return 0; }; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_17.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_17.php index 311e6b3928478..399a5a06f86e3 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_17.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_17.php @@ -5,9 +5,11 @@ use Symfony\Component\Console\Style\SymfonyStyle; //Ensure symfony style helper methods handle trailing backslashes properly when decorating user texts -return function (InputInterface $input, OutputInterface $output) { +return function (InputInterface $input, OutputInterface $output): int { $output = new SymfonyStyle($input, $output); $output->title('Title ending with \\'); $output->section('Section ending with \\'); + + return 0; }; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_18.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_18.php index d4afa45cf37c4..383615a34e666 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_18.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_18.php @@ -5,7 +5,7 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; -return function (InputInterface $input, OutputInterface $output) { +return function (InputInterface $input, OutputInterface $output): int { $output = new SymfonyStyle($input, $output); $output->definitionList( @@ -15,4 +15,6 @@ new TableSeparator(), ['foo2' => 'bar2'] ); + + return 0; }; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_19.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_19.php index e25a7ef295f45..3e57f66ca2050 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_19.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_19.php @@ -5,7 +5,9 @@ use Symfony\Component\Console\Style\SymfonyStyle; //Ensure formatting tables when using multiple headers with TableCell -return function (InputInterface $input, OutputInterface $output) { +return function (InputInterface $input, OutputInterface $output): int { $output = new SymfonyStyle($input, $output); $output->horizontalTable(['a', 'b', 'c', 'd'], [[1, 2, 3], [4, 5], [7, 8, 9]]); + + return 0; }; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_2.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_2.php index a16ad505d2bc4..5bba34f36b125 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_2.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_2.php @@ -5,7 +5,7 @@ use Symfony\Component\Console\Style\SymfonyStyle; //Ensure has single blank line between blocks -return function (InputInterface $input, OutputInterface $output) { +return function (InputInterface $input, OutputInterface $output): int { $output = new SymfonyStyle($input, $output); $output->warning('Warning'); $output->caution('Caution'); @@ -14,4 +14,6 @@ $output->note('Note'); $output->info('Info'); $output->block('Custom block', 'CUSTOM', 'fg=white;bg=green', 'X ', true); + + return 0; }; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_20.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_20.php index 6b47969eeeba6..3bdd5d5cf5b1e 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_20.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_20.php @@ -5,9 +5,11 @@ use Symfony\Component\Console\Style\SymfonyStyle; // Ensure that closing tag is applied once -return function (InputInterface $input, OutputInterface $output) { +return function (InputInterface $input, OutputInterface $output): int { $output->setDecorated(true); $output = new SymfonyStyle($input, $output); $output->write('do you want something'); $output->writeln('?'); + + return 0; }; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_21.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_21.php index 8460e7ececf37..3faf7c7a0e6db 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_21.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_21.php @@ -5,9 +5,11 @@ use Symfony\Component\Console\Style\SymfonyStyle; //Ensure texts with emojis don't make longer lines than expected -return function (InputInterface $input, OutputInterface $output) { +return function (InputInterface $input, OutputInterface $output): int { $output = new SymfonyStyle($input, $output); $output->success('Lorem ipsum dolor sit amet'); $output->success('Lorem ipsum dolor sit amet with one emoji 🎉'); $output->success('Lorem ipsum dolor sit amet with so many of them 👩‍🌾👩‍🌾👩‍🌾👩‍🌾👩‍🌾'); + + return 0; }; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_22.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_22.php index 1070394a89726..3ec61081b1126 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_22.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_22.php @@ -5,7 +5,7 @@ use Symfony\Component\Console\Style\SymfonyStyle; // ensure that nested tags have no effect on the color of the '//' prefix -return function (InputInterface $input, OutputInterface $output) { +return function (InputInterface $input, OutputInterface $output): int { $output->setDecorated(true); $output = new SymfonyStyle($input, $output); $output->block( @@ -16,4 +16,6 @@ false, false ); + + return 0; }; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_23.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_23.php index e6228fe0ba423..618de55ce3778 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_23.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_23.php @@ -4,7 +4,9 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; -return function (InputInterface $input, OutputInterface $output) { +return function (InputInterface $input, OutputInterface $output): int { $output = new SymfonyStyle($input, $output); $output->text('Hello'); + + return 0; }; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_3.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_3.php index 99253a6c08a83..b6a3cd27c56de 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_3.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_3.php @@ -5,8 +5,10 @@ use Symfony\Component\Console\Style\SymfonyStyle; //Ensure has single blank line between two titles -return function (InputInterface $input, OutputInterface $output) { +return function (InputInterface $input, OutputInterface $output): int { $output = new SymfonyStyle($input, $output); $output->title('First title'); $output->title('Second title'); + + return 0; }; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_4.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_4.php index b2f3d99546afb..d196735c14f93 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_4.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_4.php @@ -5,7 +5,7 @@ use Symfony\Component\Console\Style\SymfonyStyle; //Ensure has single blank line after any text and a title -return function (InputInterface $input, OutputInterface $output) { +return function (InputInterface $input, OutputInterface $output): int { $output = new SymfonyStyle($input, $output); $output->write('Lorem ipsum dolor sit amet'); @@ -31,4 +31,6 @@ $output->writeln('Lorem ipsum dolor sit amet'); $output->newLine(2); //Should append an extra blank line $output->title('Fifth title'); + + return 0; }; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_4_with_iterators.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_4_with_iterators.php index 3b215c7f2c5a6..24de2cab3e25d 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_4_with_iterators.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_4_with_iterators.php @@ -5,7 +5,7 @@ use Symfony\Component\Console\Style\SymfonyStyle; //Ensure has single blank line after any text and a title -return function (InputInterface $input, OutputInterface $output) { +return function (InputInterface $input, OutputInterface $output): int { $output = new SymfonyStyle($input, $output); $output->write('Lorem ipsum dolor sit amet'); @@ -31,4 +31,6 @@ $output->writeln('Lorem ipsum dolor sit amet'); $output->newLine(2); //Should append an extra blank line $output->title('Fifth title'); + + return 0; }; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_5.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_5.php index 6fba5737fce39..6fab6823374a8 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_5.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_5.php @@ -5,7 +5,7 @@ use Symfony\Component\Console\Style\SymfonyStyle; //Ensure has proper line ending before outputting a text block like with SymfonyStyle::listing() or SymfonyStyle::text() -return function (InputInterface $input, OutputInterface $output) { +return function (InputInterface $input, OutputInterface $output): int { $output = new SymfonyStyle($input, $output); $output->writeln('Lorem ipsum dolor sit amet'); @@ -34,4 +34,6 @@ 'Lorem ipsum dolor sit amet', 'consectetur adipiscing elit', ]); + + return 0; }; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_6.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_6.php index 3278f6ea05b12..cef96d5d92a9b 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_6.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_6.php @@ -5,7 +5,7 @@ use Symfony\Component\Console\Style\SymfonyStyle; //Ensure has proper blank line after text block when using a block like with SymfonyStyle::success -return function (InputInterface $input, OutputInterface $output) { +return function (InputInterface $input, OutputInterface $output): int { $output = new SymfonyStyle($input, $output); $output->listing([ @@ -13,4 +13,6 @@ 'consectetur adipiscing elit', ]); $output->success('Lorem ipsum dolor sit amet'); + + return 0; }; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_7.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_7.php index 037c6ab6b3fe5..f4f673c17793e 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_7.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_7.php @@ -5,11 +5,13 @@ use Symfony\Component\Console\Style\SymfonyStyle; //Ensure questions do not output anything when input is non-interactive -return function (InputInterface $input, OutputInterface $output) { +return function (InputInterface $input, OutputInterface $output): int { $output = new SymfonyStyle($input, $output); $output->title('Title'); $output->askHidden('Hidden question'); $output->choice('Choice question with default', ['choice1', 'choice2'], 'choice1'); $output->confirm('Confirmation with yes default', true); $output->text('Duis aute irure dolor in reprehenderit in voluptate velit esse'); + + return 0; }; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_8.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_8.php index fe9d484d252b3..8566654510506 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_8.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_8.php @@ -6,7 +6,7 @@ use Symfony\Component\Console\Style\SymfonyStyle; //Ensure formatting tables when using multiple headers with TableCell -return function (InputInterface $input, OutputInterface $output) { +return function (InputInterface $input, OutputInterface $output): int { $headers = [ [new TableCell('Main table title', ['colspan' => 3])], ['ISBN', 'Title', 'Author'], @@ -23,4 +23,6 @@ $output = new SymfonyStyle($input, $output); $output->table($headers, $rows); + + return 0; }; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_9.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_9.php index 73af4ae1e2614..77dd8d0878747 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_9.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_9.php @@ -5,7 +5,9 @@ use Symfony\Component\Console\Style\SymfonyStyle; //Ensure that all lines are aligned to the begin of the first line in a multi-line block -return function (InputInterface $input, OutputInterface $output) { +return function (InputInterface $input, OutputInterface $output): int { $output = new SymfonyStyle($input, $output); $output->block(['Custom block', 'Second custom block line'], 'CUSTOM', 'fg=white;bg=green', 'X ', true); + + return 0; }; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/interactive_command_1.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/interactive_command_1.php index 3c9c744050185..7855f9dcd2a9d 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/interactive_command_1.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/interactive_command_1.php @@ -5,7 +5,7 @@ use Symfony\Component\Console\Style\SymfonyStyle; //Ensure that questions have the expected outputs -return function (InputInterface $input, OutputInterface $output) { +return function (InputInterface $input, OutputInterface $output): int { $output = new SymfonyStyle($input, $output); $stream = fopen('php://memory', 'r+', false); @@ -16,4 +16,6 @@ $output->ask('What\'s your name?'); $output->ask('How are you?'); $output->ask('Where do you come from?'); + + return 0; }; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/progress/command_progress_iterate.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/progress/command_progress_iterate.php index 6487bc3b1fbb2..3744c9b22bddd 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/progress/command_progress_iterate.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/progress/command_progress_iterate.php @@ -5,7 +5,7 @@ use Symfony\Component\Console\Style\SymfonyStyle; // progressIterate -return function (InputInterface $input, OutputInterface $output) { +return function (InputInterface $input, OutputInterface $output): int { $style = new SymfonyStyle($input, $output); foreach ($style->progressIterate(\range(1, 10)) as $step) { @@ -13,4 +13,6 @@ } $style->writeln('end of progressbar'); + + return 0; }; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_signalable.php b/src/Symfony/Component/Console/Tests/Fixtures/application_signalable.php index 978406637aadf..c737ba1bf79c7 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_signalable.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_signalable.php @@ -23,7 +23,7 @@ public function handleSignal(int $signal, int|false $previousExitCode = 0): int| exit(0); } }) - ->setCode(function(InputInterface $input, OutputInterface $output) { + ->setCode(function(InputInterface $input, OutputInterface $output): int { $this->getHelper('question') ->ask($input, $output, new ChoiceQuestion('😊', ['y'])); diff --git a/src/Symfony/Component/Console/Tests/Helper/QuestionHelperTest.php b/src/Symfony/Component/Console/Tests/Helper/QuestionHelperTest.php index dbbf66e02ce10..0e91dd85b199e 100644 --- a/src/Symfony/Component/Console/Tests/Helper/QuestionHelperTest.php +++ b/src/Symfony/Component/Console/Tests/Helper/QuestionHelperTest.php @@ -777,7 +777,7 @@ public function testQuestionValidatorRepeatsThePrompt() $application = new Application(); $application->setAutoExit(false); $application->register('question') - ->setCode(function (InputInterface $input, OutputInterface $output) use (&$tries) { + ->setCode(function (InputInterface $input, OutputInterface $output) use (&$tries): int { $question = new Question('This is a promptable question'); $question->setValidator(function ($value) use (&$tries) { ++$tries; diff --git a/src/Symfony/Component/Console/Tests/Tester/ApplicationTesterTest.php b/src/Symfony/Component/Console/Tests/Tester/ApplicationTesterTest.php index f990e94ccac00..843f2eac7fd12 100644 --- a/src/Symfony/Component/Console/Tests/Tester/ApplicationTesterTest.php +++ b/src/Symfony/Component/Console/Tests/Tester/ApplicationTesterTest.php @@ -31,8 +31,10 @@ protected function setUp(): void $this->application->setAutoExit(false); $this->application->register('foo') ->addArgument('foo') - ->setCode(function (OutputInterface $output) { + ->setCode(function (OutputInterface $output): int { $output->writeln('foo'); + + return 0; }) ; @@ -67,11 +69,13 @@ public function testSetInputs() { $application = new Application(); $application->setAutoExit(false); - $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) { + $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output): int { $helper = new QuestionHelper(); $helper->ask($input, $output, new Question('Q1')); $helper->ask($input, $output, new Question('Q2')); $helper->ask($input, $output, new Question('Q3')); + + return 0; }); $tester = new ApplicationTester($application); @@ -93,8 +97,10 @@ public function testErrorOutput() $application->setAutoExit(false); $application->register('foo') ->addArgument('foo') - ->setCode(function (OutputInterface $output) { + ->setCode(function (OutputInterface $output): int { $output->getErrorOutput()->write('foo'); + + return 0; }) ; diff --git a/src/Symfony/Component/Console/Tests/Tester/CommandTesterTest.php b/src/Symfony/Component/Console/Tests/Tester/CommandTesterTest.php index 2e5329f8490f6..cfdebe4d88da8 100644 --- a/src/Symfony/Component/Console/Tests/Tester/CommandTesterTest.php +++ b/src/Symfony/Component/Console/Tests/Tester/CommandTesterTest.php @@ -34,7 +34,11 @@ protected function setUp(): void $this->command = new Command('foo'); $this->command->addArgument('command'); $this->command->addArgument('foo'); - $this->command->setCode(function (OutputInterface $output) { $output->writeln('foo'); }); + $this->command->setCode(function (OutputInterface $output): int { + $output->writeln('foo'); + + return 0; + }); $this->tester = new CommandTester($this->command); $this->tester->execute(['foo' => 'bar'], ['interactive' => false, 'decorated' => false, 'verbosity' => Output::VERBOSITY_VERBOSE]); @@ -94,7 +98,11 @@ public function testCommandFromApplication() $application->setAutoExit(false); $command = new Command('foo'); - $command->setCode(function (OutputInterface $output) { $output->writeln('foo'); }); + $command->setCode(function (OutputInterface $output): int { + $output->writeln('foo'); + + return 0; + }); $application->add($command); @@ -114,11 +122,13 @@ public function testCommandWithInputs() $command = new Command('foo'); $command->setHelperSet(new HelperSet([new QuestionHelper()])); - $command->setCode(function (InputInterface $input, OutputInterface $output) use ($questions, $command) { + $command->setCode(function (InputInterface $input, OutputInterface $output) use ($questions, $command): int { $helper = $command->getHelper('question'); $helper->ask($input, $output, new Question($questions[0])); $helper->ask($input, $output, new Question($questions[1])); $helper->ask($input, $output, new Question($questions[2])); + + return 0; }); $tester = new CommandTester($command); @@ -139,11 +149,13 @@ public function testCommandWithDefaultInputs() $command = new Command('foo'); $command->setHelperSet(new HelperSet([new QuestionHelper()])); - $command->setCode(function (InputInterface $input, OutputInterface $output) use ($questions, $command) { + $command->setCode(function (InputInterface $input, OutputInterface $output) use ($questions, $command): int { $helper = $command->getHelper('question'); $helper->ask($input, $output, new Question($questions[0], 'Bobby')); $helper->ask($input, $output, new Question($questions[1], 'Fine')); $helper->ask($input, $output, new Question($questions[2], 'France')); + + return 0; }); $tester = new CommandTester($command); @@ -164,12 +176,14 @@ public function testCommandWithWrongInputsNumber() $command = new Command('foo'); $command->setHelperSet(new HelperSet([new QuestionHelper()])); - $command->setCode(function (InputInterface $input, OutputInterface $output) use ($questions, $command) { + $command->setCode(function (InputInterface $input, OutputInterface $output) use ($questions, $command): int { $helper = $command->getHelper('question'); $helper->ask($input, $output, new ChoiceQuestion('choice', ['a', 'b'])); $helper->ask($input, $output, new Question($questions[0])); $helper->ask($input, $output, new Question($questions[1])); $helper->ask($input, $output, new Question($questions[2])); + + return 0; }); $tester = new CommandTester($command); @@ -191,12 +205,14 @@ public function testCommandWithQuestionsButNoInputs() $command = new Command('foo'); $command->setHelperSet(new HelperSet([new QuestionHelper()])); - $command->setCode(function (InputInterface $input, OutputInterface $output) use ($questions, $command) { + $command->setCode(function (InputInterface $input, OutputInterface $output) use ($questions, $command): int { $helper = $command->getHelper('question'); $helper->ask($input, $output, new ChoiceQuestion('choice', ['a', 'b'])); $helper->ask($input, $output, new Question($questions[0])); $helper->ask($input, $output, new Question($questions[1])); $helper->ask($input, $output, new Question($questions[2])); + + return 0; }); $tester = new CommandTester($command); @@ -216,11 +232,13 @@ public function testSymfonyStyleCommandWithInputs() ]; $command = new Command('foo'); - $command->setCode(function (InputInterface $input, OutputInterface $output) use ($questions) { + $command->setCode(function (InputInterface $input, OutputInterface $output) use ($questions): int { $io = new SymfonyStyle($input, $output); $io->ask($questions[0]); $io->ask($questions[1]); $io->ask($questions[2]); + + return 0; }); $tester = new CommandTester($command); @@ -235,8 +253,10 @@ public function testErrorOutput() $command = new Command('foo'); $command->addArgument('command'); $command->addArgument('foo'); - $command->setCode(function (OutputInterface $output) { + $command->setCode(function (OutputInterface $output): int { $output->getErrorOutput()->write('foo'); + + return 0; }); $tester = new CommandTester($command); diff --git a/src/Symfony/Component/Console/Tests/phpt/uses_stdin_as_interactive_input.phpt b/src/Symfony/Component/Console/Tests/phpt/uses_stdin_as_interactive_input.phpt index 3f329cc73f805..fedb64b61a5a0 100644 --- a/src/Symfony/Component/Console/Tests/phpt/uses_stdin_as_interactive_input.phpt +++ b/src/Symfony/Component/Console/Tests/phpt/uses_stdin_as_interactive_input.phpt @@ -17,9 +17,11 @@ require $vendor.'/vendor/autoload.php'; (new Application()) ->register('app') - ->setCode(function(InputInterface $input, OutputInterface $output) { + ->setCode(function(InputInterface $input, OutputInterface $output): int { $output->writeln((new QuestionHelper())->ask($input, $output, new Question('Foo?', 'foo'))); $output->writeln((new QuestionHelper())->ask($input, $output, new Question('Bar?', 'bar'))); + + return 0; }) ->getApplication() ->setDefaultCommand('app', true) diff --git a/src/Symfony/Component/Console/composer.json b/src/Symfony/Component/Console/composer.json index 083036d5cf654..6247ee94e9a1d 100644 --- a/src/Symfony/Component/Console/composer.json +++ b/src/Symfony/Component/Console/composer.json @@ -43,7 +43,8 @@ "symfony/dotenv": "<6.4", "symfony/event-dispatcher": "<6.4", "symfony/lock": "<6.4", - "symfony/process": "<6.4" + "symfony/process": "<6.4", + "symfony/runtime": "<7.3" }, "autoload": { "psr-4": { "Symfony\\Component\\Console\\": "" }, diff --git a/src/Symfony/Component/Runtime/Tests/phpt/application.php b/src/Symfony/Component/Runtime/Tests/phpt/application.php index 1e1014e9f3e5a..ca2de555edfb7 100644 --- a/src/Symfony/Component/Runtime/Tests/phpt/application.php +++ b/src/Symfony/Component/Runtime/Tests/phpt/application.php @@ -18,8 +18,10 @@ return function (array $context) { $command = new Command('go'); - $command->setCode(function (InputInterface $input, OutputInterface $output) use ($context) { + $command->setCode(function (InputInterface $input, OutputInterface $output) use ($context): int { $output->write('OK Application '.$context['SOME_VAR']); + + return 0; }); $app = new Application(); diff --git a/src/Symfony/Component/Runtime/Tests/phpt/command.php b/src/Symfony/Component/Runtime/Tests/phpt/command.php index 3a5fa11e00000..e307d195b113e 100644 --- a/src/Symfony/Component/Runtime/Tests/phpt/command.php +++ b/src/Symfony/Component/Runtime/Tests/phpt/command.php @@ -19,7 +19,9 @@ return function (Command $command, InputInterface $input, OutputInterface $output, array $context) { $command->addOption('hello', 'e', InputOption::VALUE_REQUIRED, 'How should I greet?', 'OK'); - return $command->setCode(function () use ($input, $output, $context) { + return $command->setCode(function () use ($input, $output, $context): int { $output->write($input->getOption('hello').' Command '.$context['SOME_VAR']); + + return 0; }); }; diff --git a/src/Symfony/Component/Runtime/Tests/phpt/dotenv_overload_command_debug_exists_0_to_1.php b/src/Symfony/Component/Runtime/Tests/phpt/dotenv_overload_command_debug_exists_0_to_1.php index af6409dda62bc..2968e37ea02f4 100644 --- a/src/Symfony/Component/Runtime/Tests/phpt/dotenv_overload_command_debug_exists_0_to_1.php +++ b/src/Symfony/Component/Runtime/Tests/phpt/dotenv_overload_command_debug_exists_0_to_1.php @@ -20,6 +20,8 @@ require __DIR__.'/autoload.php'; -return static fn (Command $command, OutputInterface $output, array $context): Command => $command->setCode(static function () use ($output, $context): void { +return static fn (Command $command, OutputInterface $output, array $context): Command => $command->setCode(static function () use ($output, $context): int { $output->writeln($context['DEBUG_ENABLED']); + + return 0; }); diff --git a/src/Symfony/Component/Runtime/Tests/phpt/dotenv_overload_command_debug_exists_1_to_0.php b/src/Symfony/Component/Runtime/Tests/phpt/dotenv_overload_command_debug_exists_1_to_0.php index 78a0bf29448b8..1f2fa3590e16f 100644 --- a/src/Symfony/Component/Runtime/Tests/phpt/dotenv_overload_command_debug_exists_1_to_0.php +++ b/src/Symfony/Component/Runtime/Tests/phpt/dotenv_overload_command_debug_exists_1_to_0.php @@ -20,6 +20,8 @@ require __DIR__.'/autoload.php'; -return static fn (Command $command, OutputInterface $output, array $context): Command => $command->setCode(static function () use ($output, $context): void { +return static fn (Command $command, OutputInterface $output, array $context): Command => $command->setCode(static function () use ($output, $context): int { $output->writeln($context['DEBUG_MODE']); + + return 0; }); diff --git a/src/Symfony/Component/Runtime/Tests/phpt/dotenv_overload_command_env_exists.php b/src/Symfony/Component/Runtime/Tests/phpt/dotenv_overload_command_env_exists.php index 3e72372e5af06..8587f20f2382b 100644 --- a/src/Symfony/Component/Runtime/Tests/phpt/dotenv_overload_command_env_exists.php +++ b/src/Symfony/Component/Runtime/Tests/phpt/dotenv_overload_command_env_exists.php @@ -20,6 +20,8 @@ require __DIR__.'/autoload.php'; -return static fn (Command $command, OutputInterface $output, array $context): Command => $command->setCode(static function () use ($output, $context): void { +return static fn (Command $command, OutputInterface $output, array $context): Command => $command->setCode(static function () use ($output, $context): int { $output->writeln($context['ENV_MODE']); + + return 0; }); diff --git a/src/Symfony/Component/Runtime/Tests/phpt/dotenv_overload_command_no_debug.php b/src/Symfony/Component/Runtime/Tests/phpt/dotenv_overload_command_no_debug.php index 3fe4f44d7967b..4ab7694298f95 100644 --- a/src/Symfony/Component/Runtime/Tests/phpt/dotenv_overload_command_no_debug.php +++ b/src/Symfony/Component/Runtime/Tests/phpt/dotenv_overload_command_no_debug.php @@ -19,6 +19,8 @@ require __DIR__.'/autoload.php'; -return static fn (Command $command, OutputInterface $output, array $context): Command => $command->setCode(static function () use ($output, $context): void { +return static fn (Command $command, OutputInterface $output, array $context): Command => $command->setCode(static function () use ($output, $context): int { $output->writeln($context['DEBUG_ENABLED']); + + return 0; });