diff --git a/Application.php b/Application.php index 3c6314f82..6ea018a19 100644 --- a/Application.php +++ b/Application.php @@ -797,7 +797,7 @@ public function find(string $name): Command foreach ($abbrevs as $abbrev) { $maxLen = max(Helper::width($abbrev), $maxLen); } - $abbrevs = array_map(function ($cmd) use ($commandList, $usableWidth, $maxLen, &$commands) { + $abbrevs = array_map(static function ($cmd) use ($commandList, $usableWidth, $maxLen, &$commands) { if ($commandList[$cmd]->isHidden()) { unset($commands[array_search($cmd, $commands)]); @@ -912,7 +912,7 @@ protected function doRenderThrowable(\Throwable $e, OutputInterface $output): vo } if (str_contains($message, "@anonymous\0")) { - $message = preg_replace_callback('/[a-zA-Z_\x7f-\xff][\\\\a-zA-Z0-9_\x7f-\xff]*+@anonymous\x00.*?\.php(?:0x?|:[0-9]++\$)?[0-9a-fA-F]++/', fn ($m) => class_exists($m[0], false) ? (get_parent_class($m[0]) ?: key(class_implements($m[0])) ?: 'class').'@anonymous' : $m[0], $message); + $message = preg_replace_callback('/[a-zA-Z_\x7f-\xff][\\\\a-zA-Z0-9_\x7f-\xff]*+@anonymous\x00.*?\.php(?:0x?|:[0-9]++\$)?[0-9a-fA-F]++/', static fn ($m) => class_exists($m[0], false) ? (get_parent_class($m[0]) ?: key(class_implements($m[0])) ?: 'class').'@anonymous' : $m[0], $message); } $width = $this->terminal->getWidth() ? $this->terminal->getWidth() - 1 : \PHP_INT_MAX; @@ -1252,7 +1252,7 @@ private function findAlternatives(string $name, iterable $collection): array } } - $alternatives = array_filter($alternatives, fn ($lev) => $lev < 2 * $threshold); + $alternatives = array_filter($alternatives, static fn ($lev) => $lev < 2 * $threshold); ksort($alternatives, \SORT_NATURAL | \SORT_FLAG_CASE); return array_keys($alternatives); diff --git a/Attribute/Ask.php b/Attribute/Ask.php index 5961953ae..360a08421 100644 --- a/Attribute/Ask.php +++ b/Attribute/Ask.php @@ -95,9 +95,7 @@ public static function tryFrom(\ReflectionParameter|\ReflectionProperty $member, $question->setTimeout($self->timeout); if (!$self->validator && $reflection->isProperty() && 'array' !== $type->getName()) { - $self->validator = function (mixed $value) use ($reflection): mixed { - return $this->{$reflection->getName()} = $value; - }; + $self->validator = fn (mixed $value): mixed => $this->{$reflection->getName()} = $value; } $question->setValidator($self->validator); @@ -108,7 +106,7 @@ public static function tryFrom(\ReflectionParameter|\ReflectionProperty $member, } elseif (is_subclass_of($type->getName(), \BackedEnum::class)) { /** @var class-string<\BackedEnum> $backedType */ $backedType = $reflection->getType()->getName(); - $question->setNormalizer(fn (string|int $value) => $backedType::tryFrom($value) ?? throw InvalidArgumentException::fromEnumValue($reflection->getName(), $value, array_column($backedType::cases(), 'value'))); + $question->setNormalizer(static fn (string|int $value) => $backedType::tryFrom($value) ?? throw InvalidArgumentException::fromEnumValue($reflection->getName(), $value, array_column($backedType::cases(), 'value'))); } if ('array' === $type->getName()) { diff --git a/Command/CompleteCommand.php b/Command/CompleteCommand.php index a6ce1d168..44d23cc63 100644 --- a/Command/CompleteCommand.php +++ b/Command/CompleteCommand.php @@ -149,7 +149,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->log('Suggestions:'); if ($options = $suggestions->getOptionSuggestions()) { - $this->log(' --'.implode(' --', array_map(fn ($o) => $o->getName(), $options))); + $this->log(' --'.implode(' --', array_map(static fn ($o) => $o->getName(), $options))); } elseif ($values = $suggestions->getValueSuggestions()) { $this->log(' '.implode(' ', $values)); } else { diff --git a/Command/DumpCompletionCommand.php b/Command/DumpCompletionCommand.php index 1671120a3..17041df91 100644 --- a/Command/DumpCompletionCommand.php +++ b/Command/DumpCompletionCommand.php @@ -123,7 +123,7 @@ private function tailDebugLog(string $commandName, OutputInterface $output): voi touch($debugFile); } $process = new Process(['tail', '-f', $debugFile], null, null, null, 0); - $process->run(function (string $type, string $line) use ($output): void { + $process->run(static function (string $type, string $line) use ($output): void { $output->write($line); }); } diff --git a/Command/HelpCommand.php b/Command/HelpCommand.php index a5a54b4e2..2bf972cad 100644 --- a/Command/HelpCommand.php +++ b/Command/HelpCommand.php @@ -35,7 +35,7 @@ protected function configure(): void ->setName('help') ->setDefinition([ new InputArgument('command_name', InputArgument::OPTIONAL, 'The command name', 'help', fn () => array_keys((new ApplicationDescription($this->getApplication()))->getCommands())), - new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt', fn () => (new DescriptorHelper())->getFormats()), + new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt', static fn () => (new DescriptorHelper())->getFormats()), new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command help'), ]) ->setDescription('Display help for a command') diff --git a/Command/InvokableCommand.php b/Command/InvokableCommand.php index da358753b..016da5a01 100644 --- a/Command/InvokableCommand.php +++ b/Command/InvokableCommand.php @@ -93,10 +93,10 @@ public function configure(InputDefinition $definition): void } if ($input = MapInput::tryFrom($parameter)) { - $inputArguments = array_map(fn (Argument $a) => $a->toInputArgument(), iterator_to_array($input->getArguments(), false)); + $inputArguments = array_map(static fn (Argument $a) => $a->toInputArgument(), iterator_to_array($input->getArguments(), false)); // make sure optional arguments are defined after required ones - usort($inputArguments, fn (InputArgument $a, InputArgument $b) => (int) $b->isRequired() - (int) $a->isRequired()); + usort($inputArguments, static fn (InputArgument $a, InputArgument $b) => (int) $b->isRequired() - (int) $a->isRequired()); foreach ($inputArguments as $inputArgument) { $definition->addArgument($inputArgument); diff --git a/Command/ListCommand.php b/Command/ListCommand.php index 789a8d9ac..c120d13f9 100644 --- a/Command/ListCommand.php +++ b/Command/ListCommand.php @@ -32,7 +32,7 @@ protected function configure(): void ->setDefinition([ new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name', null, fn () => array_keys((new ApplicationDescription($this->getApplication()))->getNamespaces())), new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list'), - new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt', fn () => (new DescriptorHelper())->getFormats()), + new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt', static fn () => (new DescriptorHelper())->getFormats()), new InputOption('short', null, InputOption::VALUE_NONE, 'To skip describing commands\' arguments'), ]) ->setDescription('List commands') diff --git a/Command/TraceableCommand.php b/Command/TraceableCommand.php index 8129ca803..2cf190e26 100644 --- a/Command/TraceableCommand.php +++ b/Command/TraceableCommand.php @@ -63,9 +63,7 @@ public function __construct( parent::__construct($command->getName()); // init below enables calling {@see parent::run()} - [$code, $processTitle, $ignoreValidationErrors] = \Closure::bind(function () { - return [$this->code, $this->processTitle, $this->ignoreValidationErrors]; - }, $command, Command::class)(); + [$code, $processTitle, $ignoreValidationErrors] = \Closure::bind(fn () => [$this->code, $this->processTitle, $this->ignoreValidationErrors], $command, Command::class)(); if (\is_callable($code)) { $this->setCode($code); @@ -169,9 +167,7 @@ public function complete(CompletionInput $input, CompletionSuggestions $suggesti public function setCode(callable $code): static { if ($code instanceof InvokableCommand) { - $r = \Closure::bind(function () { - return $this->invokable; - }, $code, InvokableCommand::class)(); + $r = \Closure::bind(fn () => $this->invokable, $code, InvokableCommand::class)(); $this->invokableCommandInfo = [ 'class' => $r->getClosureScopeClass()->name, diff --git a/Descriptor/MarkdownDescriptor.php b/Descriptor/MarkdownDescriptor.php index 8b7075943..15fad8de4 100644 --- a/Descriptor/MarkdownDescriptor.php +++ b/Descriptor/MarkdownDescriptor.php @@ -106,7 +106,7 @@ protected function describeCommand(Command $command, array $options = []): void .str_repeat('-', Helper::width($command->getName()) + 2)."\n\n" .($command->getDescription() ? $command->getDescription()."\n\n" : '') .'### Usage'."\n\n" - .array_reduce($command->getAliases(), fn ($carry, $usage) => $carry.'* `'.$usage.'`'."\n") + .array_reduce($command->getAliases(), static fn ($carry, $usage) => $carry.'* `'.$usage.'`'."\n") ); return; @@ -119,7 +119,7 @@ protected function describeCommand(Command $command, array $options = []): void .str_repeat('-', Helper::width($command->getName()) + 2)."\n\n" .($command->getDescription() ? $command->getDescription()."\n\n" : '') .'### Usage'."\n\n" - .array_reduce(array_merge([$command->getSynopsis()], $command->getAliases(), $command->getUsages()), fn ($carry, $usage) => $carry.'* `'.$usage.'`'."\n") + .array_reduce(array_merge([$command->getSynopsis()], $command->getAliases(), $command->getUsages()), static fn ($carry, $usage) => $carry.'* `'.$usage.'`'."\n") ); if ($help = $command->getProcessedHelp()) { @@ -149,7 +149,7 @@ protected function describeApplication(Application $application, array $options } $this->write("\n\n"); - $this->write(implode("\n", array_map(fn ($commandName) => \sprintf('* [`%s`](#%s)', $commandName, str_replace(':', '', $description->getCommand($commandName)->getName())), $namespace['commands']))); + $this->write(implode("\n", array_map(static fn ($commandName) => \sprintf('* [`%s`](#%s)', $commandName, str_replace(':', '', $description->getCommand($commandName)->getName())), $namespace['commands']))); } foreach ($description->getCommands() as $command) { diff --git a/Descriptor/TextDescriptor.php b/Descriptor/TextDescriptor.php index 51c411f46..226d87aee 100644 --- a/Descriptor/TextDescriptor.php +++ b/Descriptor/TextDescriptor.php @@ -193,7 +193,7 @@ protected function describeApplication(Application $application, array $options } // calculate max. width based on available commands per namespace - $width = $this->getColumnWidth(array_merge(...array_values(array_map(fn ($namespace) => array_intersect($namespace['commands'], array_keys($commands)), array_values($namespaces))))); + $width = $this->getColumnWidth(array_merge(...array_values(array_map(static fn ($namespace) => array_intersect($namespace['commands'], array_keys($commands)), array_values($namespaces))))); if ($describedNamespace) { $this->writeText(\sprintf('Available commands for the "%s" namespace:', $describedNamespace), $options); @@ -202,7 +202,7 @@ protected function describeApplication(Application $application, array $options } foreach ($namespaces as $namespace) { - $namespace['commands'] = array_filter($namespace['commands'], fn ($name) => isset($commands[$name])); + $namespace['commands'] = array_filter($namespace['commands'], static fn ($name) => isset($commands[$name])); if (!$namespace['commands']) { continue; diff --git a/Helper/Dumper.php b/Helper/Dumper.php index 0cd01e616..2c7051939 100644 --- a/Helper/Dumper.php +++ b/Helper/Dumper.php @@ -36,7 +36,7 @@ public function __construct( return rtrim($dumper->dump(($this->cloner ??= new VarCloner())->cloneVar($var)->withRefHandles(false), true)); }; } else { - $this->handler = fn ($var): string => match (true) { + $this->handler = static fn ($var): string => match (true) { null === $var => 'null', true === $var => 'true', false === $var => 'false', diff --git a/Helper/ProgressBar.php b/Helper/ProgressBar.php index 3e0c74ab9..c742e2b3b 100644 --- a/Helper/ProgressBar.php +++ b/Helper/ProgressBar.php @@ -566,7 +566,7 @@ private function determineBestFormat(): string private static function initPlaceholderFormatters(): array { return [ - 'bar' => function (self $bar, OutputInterface $output) { + 'bar' => static function (self $bar, OutputInterface $output) { $completeBars = $bar->getBarOffset(); $display = str_repeat($bar->getBarCharacter(), $completeBars); if ($completeBars < $bar->getBarWidth()) { @@ -576,25 +576,25 @@ private static function initPlaceholderFormatters(): array return $display; }, - 'elapsed' => fn (self $bar) => Helper::formatTime(time() - $bar->getStartTime(), 2), - 'remaining' => function (self $bar) { + 'elapsed' => static fn (self $bar) => Helper::formatTime(time() - $bar->getStartTime(), 2), + 'remaining' => static function (self $bar) { if (null === $bar->max) { throw new LogicException('Unable to display the remaining time if the maximum number of steps is not set.'); } return Helper::formatTime($bar->getRemaining(), 2); }, - 'estimated' => function (self $bar) { + 'estimated' => static function (self $bar) { if (null === $bar->max) { throw new LogicException('Unable to display the estimated time if the maximum number of steps is not set.'); } return Helper::formatTime($bar->getEstimated(), 2); }, - 'memory' => fn (self $bar) => Helper::formatMemory(memory_get_usage(true)), - 'current' => fn (self $bar) => str_pad($bar->getProgress(), $bar->getStepWidth(), ' ', \STR_PAD_LEFT), - 'max' => fn (self $bar) => $bar->getMaxSteps(), - 'percent' => fn (self $bar) => floor($bar->getProgressPercent() * 100), + 'memory' => static fn (self $bar) => Helper::formatMemory(memory_get_usage(true)), + 'current' => static fn (self $bar) => str_pad($bar->getProgress(), $bar->getStepWidth(), ' ', \STR_PAD_LEFT), + 'max' => static fn (self $bar) => $bar->getMaxSteps(), + 'percent' => static fn (self $bar) => floor($bar->getProgressPercent() * 100), ]; } diff --git a/Helper/ProgressIndicator.php b/Helper/ProgressIndicator.php index 849c0589c..3bd6feda2 100644 --- a/Helper/ProgressIndicator.php +++ b/Helper/ProgressIndicator.php @@ -238,10 +238,10 @@ private function getCurrentTimeInMilliseconds(): float private static function initPlaceholderFormatters(): array { return [ - 'indicator' => fn (self $indicator) => $indicator->finished ? $indicator->finishedIndicatorValue : $indicator->indicatorValues[$indicator->indicatorCurrent % \count($indicator->indicatorValues)], - 'message' => fn (self $indicator) => $indicator->message, - 'elapsed' => fn (self $indicator) => Helper::formatTime(time() - $indicator->startTime, 2), - 'memory' => fn () => Helper::formatMemory(memory_get_usage(true)), + 'indicator' => static fn (self $indicator) => $indicator->finished ? $indicator->finishedIndicatorValue : $indicator->indicatorValues[$indicator->indicatorCurrent % \count($indicator->indicatorValues)], + 'message' => static fn (self $indicator) => $indicator->message, + 'elapsed' => static fn (self $indicator) => Helper::formatTime(time() - $indicator->startTime, 2), + 'memory' => static fn () => Helper::formatMemory(memory_get_usage(true)), ]; } } diff --git a/Helper/QuestionHelper.php b/Helper/QuestionHelper.php index ee285ff57..31c46faf6 100644 --- a/Helper/QuestionHelper.php +++ b/Helper/QuestionHelper.php @@ -313,7 +313,7 @@ private function autocomplete(OutputInterface $output, Question $question, $inpu $matches = array_filter( $autocomplete($ret), - fn ($match) => '' === $ret || str_starts_with($match, $ret) + static fn ($match) => '' === $ret || str_starts_with($match, $ret) ); $numMatches = \count($matches); $ofs = -1; diff --git a/Input/Input.php b/Input/Input.php index d2881c60f..ed86c06a8 100644 --- a/Input/Input.php +++ b/Input/Input.php @@ -63,7 +63,7 @@ public function validate(): void $definition = $this->definition; $givenArguments = $this->arguments; - $missingArguments = array_filter(array_keys($definition->getArguments()), fn ($argument) => !\array_key_exists($argument, $givenArguments) && $definition->getArgument($argument)->isRequired()); + $missingArguments = array_filter(array_keys($definition->getArguments()), static fn ($argument) => !\array_key_exists($argument, $givenArguments) && $definition->getArgument($argument)->isRequired()); if (\count($missingArguments) > 0) { throw new RuntimeException(\sprintf('Not enough arguments (missing: "%s").', implode(', ', $missingArguments))); diff --git a/Question/ConfirmationQuestion.php b/Question/ConfirmationQuestion.php index 951d68140..ddbf3407b 100644 --- a/Question/ConfirmationQuestion.php +++ b/Question/ConfirmationQuestion.php @@ -41,7 +41,7 @@ private function getDefaultNormalizer(): callable $default = $this->getDefault(); $regex = $this->trueAnswerRegex; - return function ($answer) use ($default, $regex) { + return static function ($answer) use ($default, $regex) { if (\is_bool($answer)) { return $answer; } diff --git a/Resources/completion.bash b/Resources/completion.bash index 2befe76cb..a32338e18 100644 --- a/Resources/completion.bash +++ b/Resources/completion.bash @@ -54,7 +54,7 @@ _sf_{{ COMMAND_NAME }}() { done local sfcomplete - if sfcomplete=$(${completecmd[@]} 2>&1); then + if sfcomplete=$(SHELL_VERBOSITY=0 ${completecmd[@]} 2>&1); then local quote suggestions quote=${cur:0:1} diff --git a/Resources/completion.fish b/Resources/completion.fish index 1853dd80f..d2309b36f 100644 --- a/Resources/completion.fish +++ b/Resources/completion.fish @@ -19,7 +19,11 @@ function _sf_{{ COMMAND_NAME }} set completecmd $completecmd "-c$c" - $completecmd + set sfcomplete (env SHELL_VERBOSITY=0 $completecmd) + + for i in $sfcomplete + echo $i + end end complete -c '{{ COMMAND_NAME }}' -a '(_sf_{{ COMMAND_NAME }})' -f diff --git a/Resources/completion.zsh b/Resources/completion.zsh index ff76fe5fa..eabeefb50 100644 --- a/Resources/completion.zsh +++ b/Resources/completion.zsh @@ -59,7 +59,7 @@ _sf_{{ COMMAND_NAME }}() { fi # Use eval to handle any environment variables and such - out=$(eval ${requestComp} 2>/dev/null) + out=$(eval SHELL_VERBOSITY=0 ${requestComp} 2>/dev/null) while IFS='\n' read -r comp; do if [ -n "$comp" ]; then diff --git a/SignalRegistry/SignalMap.php b/SignalRegistry/SignalMap.php index 2f9aa67c1..f696377f4 100644 --- a/SignalRegistry/SignalMap.php +++ b/SignalRegistry/SignalMap.php @@ -27,7 +27,7 @@ public static function getSignalName(int $signal): ?string if (!isset(self::$map)) { $r = new \ReflectionExtension('pcntl'); $c = $r->getConstants(); - $map = array_filter($c, fn ($k) => str_starts_with($k, 'SIG') && !str_starts_with($k, 'SIG_') && 'SIGBABY' !== $k, \ARRAY_FILTER_USE_KEY); + $map = array_filter($c, static fn ($k) => str_starts_with($k, 'SIG') && !str_starts_with($k, 'SIG_') && 'SIGBABY' !== $k, \ARRAY_FILTER_USE_KEY); self::$map = array_flip($map); } diff --git a/Tests/ApplicationTest.php b/Tests/ApplicationTest.php index 420711735..ed94a7031 100644 --- a/Tests/ApplicationTest.php +++ b/Tests/ApplicationTest.php @@ -192,7 +192,7 @@ public function testAllWithCommandLoader() $this->assertCount(1, $commands, '->all() takes a namespace as its first argument'); $application->setCommandLoader(new FactoryCommandLoader([ - 'foo:bar1' => fn () => new \Foo1Command(), + 'foo:bar1' => static fn () => new \Foo1Command(), ])); $commands = $application->all('foo'); $this->assertCount(2, $commands, '->all() takes a namespace as its first argument'); @@ -209,7 +209,7 @@ public function testRegister() public function testRegisterAmbiguous() { - $code = function (InputInterface $input, OutputInterface $output): int { + $code = static function (InputInterface $input, OutputInterface $output): int { $output->writeln('It works!'); return 0; @@ -294,7 +294,7 @@ public function testAddCommandThrowsExceptionOnInvalidCommand(callable $command, public static function provideInvalidInvokableCommands(): iterable { yield 'a function' => ['strlen', InvalidArgumentException::class, \sprintf('The command must be an instance of "%s" or an invokable object.', Command::class)]; - yield 'a closure' => [function () { + yield 'a closure' => [static function () { }, InvalidArgumentException::class, \sprintf('The command must be an instance of "%s" or an invokable object.', Command::class)]; yield 'without the #[AsCommand] attribute' => [new class { public function __invoke() @@ -336,7 +336,7 @@ public function testHasGetWithCommandLoader() $this->assertEquals($foo, $application->get('afoobar'), '->get() returns a command by alias'); $application->setCommandLoader(new FactoryCommandLoader([ - 'foo:bar1' => fn () => new \Foo1Command(), + 'foo:bar1' => static fn () => new \Foo1Command(), ])); $this->assertTrue($application->has('afoobar'), '->has() returns true if an instance is registered for an alias even with command loader'); @@ -500,7 +500,7 @@ public function testFindWithCommandLoader() { $application = new Application(); $application->setCommandLoader(new FactoryCommandLoader([ - 'foo:bar' => $f = fn () => new \FooCommand(), + 'foo:bar' => $f = static fn () => new \FooCommand(), ])); $this->assertInstanceOf(\FooCommand::class, $application->find('foo:bar'), '->find() returns a command if its name exists'); @@ -892,7 +892,7 @@ public function testSetCatchErrors(bool $catchExceptions) $application = new Application(); $application->setAutoExit(false); $application->setCatchExceptions($catchExceptions); - $application->addCommand((new Command('boom'))->setCode(fn () => throw new \Error('This is an error.'))); + $application->addCommand((new Command('boom'))->setCode(static fn () => throw new \Error('This is an error.'))); putenv('COLUMNS=120'); $tester = new ApplicationTester($application); @@ -969,7 +969,7 @@ public function testRenderExceptionWithDoubleWidthCharacters() $application = new Application(); $application->setAutoExit(false); putenv('COLUMNS=120'); - $application->register('foo')->setCode(function () { + $application->register('foo')->setCode(static function () { throw new \Exception('エラーメッセージ'); }); $tester = new ApplicationTester($application); @@ -983,7 +983,7 @@ public function testRenderExceptionWithDoubleWidthCharacters() $application = new Application(); $application->setAutoExit(false); putenv('COLUMNS=32'); - $application->register('foo')->setCode(function () { + $application->register('foo')->setCode(static function () { throw new \Exception('コマンドの実行中にエラーが発生しました。'); }); $tester = new ApplicationTester($application); @@ -997,7 +997,7 @@ public function testRenderExceptionEscapesLines() $application = new Application(); $application->setAutoExit(false); putenv('COLUMNS=22'); - $application->register('foo')->setCode(function () { + $application->register('foo')->setCode(static function () { throw new \Exception('dont break here !'); }); $tester = new ApplicationTester($application); @@ -1016,7 +1016,7 @@ public function getTerminalWidth(): int } }; $application->setAutoExit(false); - $application->register('foo')->setCode(function () { + $application->register('foo')->setCode(static function () { throw new \InvalidArgumentException("\n\nline 1 with extra spaces \nline 2\n\nline 4\n"); }); $tester = new ApplicationTester($application); @@ -1030,7 +1030,7 @@ public function testRenderAnonymousException() { $application = new Application(); $application->setAutoExit(false); - $application->register('foo')->setCode(function () { + $application->register('foo')->setCode(static function () { throw new class('') extends \InvalidArgumentException {}; }); $tester = new ApplicationTester($application); @@ -1040,7 +1040,7 @@ public function testRenderAnonymousException() $application = new Application(); $application->setAutoExit(false); - $application->register('foo')->setCode(function () { + $application->register('foo')->setCode(static function () { throw new \InvalidArgumentException(\sprintf('Dummy type "%s" is invalid.', (new class {})::class)); }); $tester = new ApplicationTester($application); @@ -1054,7 +1054,7 @@ public function testRenderExceptionStackTraceContainsRootException() { $application = new Application(); $application->setAutoExit(false); - $application->register('foo')->setCode(function () { + $application->register('foo')->setCode(static function () { throw new class('') extends \InvalidArgumentException {}; }); $tester = new ApplicationTester($application); @@ -1064,7 +1064,7 @@ public function testRenderExceptionStackTraceContainsRootException() $application = new Application(); $application->setAutoExit(false); - $application->register('foo')->setCode(function () { + $application->register('foo')->setCode(static function () { throw new \InvalidArgumentException(\sprintf('Dummy type "%s" is invalid.', (new class {})::class)); }); $tester = new ApplicationTester($application); @@ -1079,7 +1079,7 @@ public function testRenderExceptionEscapesLinesOfSynopsis() $application->setAutoExit(false); $application ->register('foo') - ->setCode(function () { + ->setCode(static function () { throw new \Exception('some exception'); }) ->addArgument('info') @@ -1251,7 +1251,7 @@ public function testRunDispatchesIntegerExitCode() // We can assume here that some other test asserts that the event is dispatched at all $dispatcher = new EventDispatcher(); - $dispatcher->addListener('console.terminate', function (ConsoleTerminateEvent $event) use (&$passedRightValue) { + $dispatcher->addListener('console.terminate', static function (ConsoleTerminateEvent $event) use (&$passedRightValue) { $passedRightValue = (4 === $event->getExitCode()); }); @@ -1259,7 +1259,7 @@ public function testRunDispatchesIntegerExitCode() $application->setDispatcher($dispatcher); $application->setAutoExit(false); - $application->register('test')->setCode(function (InputInterface $input, OutputInterface $output) { + $application->register('test')->setCode(static function (InputInterface $input, OutputInterface $output) { throw new \Exception('', 4); }); @@ -1290,7 +1290,7 @@ public function testRunDispatchesExitCodeOneForExceptionCodeZero() // We can assume here that some other test asserts that the event is dispatched at all $dispatcher = new EventDispatcher(); - $dispatcher->addListener('console.terminate', function (ConsoleTerminateEvent $event) use (&$passedRightValue) { + $dispatcher->addListener('console.terminate', static function (ConsoleTerminateEvent $event) use (&$passedRightValue) { $passedRightValue = (1 === $event->getExitCode()); }); @@ -1298,7 +1298,7 @@ public function testRunDispatchesExitCodeOneForExceptionCodeZero() $application->setDispatcher($dispatcher); $application->setAutoExit(false); - $application->register('test')->setCode(function (InputInterface $input, OutputInterface $output) { + $application->register('test')->setCode(static function (InputInterface $input, OutputInterface $output) { throw new \Exception(); }); @@ -1339,9 +1339,7 @@ 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): int { - return 0; - }) + ->setCode(static fn (InputInterface $input, OutputInterface $output): int => 0) ; $input = new ArrayInput(['command' => 'foo']); @@ -1362,9 +1360,7 @@ public function testAddingAlreadySetDefinitionElementData($def) $application ->register('foo') ->setDefinition([$def]) - ->setCode(function (InputInterface $input, OutputInterface $output): int { - return 0; - }) + ->setCode(static fn (InputInterface $input, OutputInterface $output): int => 0) ; $input = new ArrayInput(['command' => 'foo']); @@ -1526,7 +1522,7 @@ public function testRunWithDispatcher() $application->setAutoExit(false); $application->setDispatcher($this->getDispatcher()); - $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output): int { + $application->register('foo')->setCode(static function (InputInterface $input, OutputInterface $output): int { $output->write('foo.'); return 0; @@ -1544,7 +1540,7 @@ public function testRunWithExceptionAndDispatcher() $application->setAutoExit(false); $application->setCatchExceptions(false); - $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) { + $application->register('foo')->setCode(static function (InputInterface $input, OutputInterface $output) { throw new \RuntimeException('foo'); }); @@ -1562,7 +1558,7 @@ public function testRunDispatchesAllEventsWithException() $application->setDispatcher($this->getDispatcher()); $application->setAutoExit(false); - $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) { + $application->register('foo')->setCode(static function (InputInterface $input, OutputInterface $output) { $output->write('foo.'); throw new \RuntimeException('foo'); @@ -1576,7 +1572,7 @@ public function testRunDispatchesAllEventsWithException() public function testRunDispatchesAllEventsWithExceptionInListener() { $dispatcher = $this->getDispatcher(); - $dispatcher->addListener('console.command', function () { + $dispatcher->addListener('console.command', static function () { throw new \RuntimeException('foo'); }); @@ -1584,7 +1580,7 @@ public function testRunDispatchesAllEventsWithExceptionInListener() $application->setDispatcher($dispatcher); $application->setAutoExit(false); - $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output): int { + $application->register('foo')->setCode(static function (InputInterface $input, OutputInterface $output): int { $output->write('foo.'); return 0; @@ -1601,7 +1597,7 @@ public function testRunWithError() $application->setAutoExit(false); $application->setCatchExceptions(false); - $application->register('dym')->setCode(function (InputInterface $input, OutputInterface $output) { + $application->register('dym')->setCode(static function (InputInterface $input, OutputInterface $output) { $output->write('dym.'); throw new \Error('dymerr'); @@ -1640,13 +1636,13 @@ public function testRunWithFindError() public function testRunAllowsErrorListenersToSilenceTheException() { $dispatcher = $this->getDispatcher(); - $dispatcher->addListener('console.error', function (ConsoleErrorEvent $event) { + $dispatcher->addListener('console.error', static function (ConsoleErrorEvent $event) { $event->getOutput()->write('silenced.'); $event->setExitCode(0); }); - $dispatcher->addListener('console.command', function () { + $dispatcher->addListener('console.command', static function () { throw new \RuntimeException('foo'); }); @@ -1654,7 +1650,7 @@ public function testRunAllowsErrorListenersToSilenceTheException() $application->setDispatcher($dispatcher); $application->setAutoExit(false); - $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output): int { + $application->register('foo')->setCode(static function (InputInterface $input, OutputInterface $output): int { $output->write('foo.'); return 0; @@ -1692,7 +1688,7 @@ public function testErrorIsRethrownIfNotHandledByConsoleErrorEvent() $application->setCatchExceptions(false); $application->setDispatcher(new EventDispatcher()); - $application->register('dym')->setCode(function () { + $application->register('dym')->setCode(static function () { throw new \Error('Something went wrong.'); }); @@ -1713,7 +1709,7 @@ public function testRunWithErrorAndDispatcher() $application->setAutoExit(false); $application->setCatchExceptions(false); - $application->register('dym')->setCode(function (InputInterface $input, OutputInterface $output) { + $application->register('dym')->setCode(static function (InputInterface $input, OutputInterface $output) { $output->write('dym.'); throw new \Error('dymerr'); @@ -1734,7 +1730,7 @@ public function testRunDispatchesAllEventsWithError() $application->setDispatcher($this->getDispatcher()); $application->setAutoExit(false); - $application->register('dym')->setCode(function (InputInterface $input, OutputInterface $output) { + $application->register('dym')->setCode(static function (InputInterface $input, OutputInterface $output) { $output->write('dym.'); throw new \Error('dymerr'); @@ -1751,7 +1747,7 @@ public function testRunWithErrorFailingStatusCode() $application->setDispatcher($this->getDispatcher()); $application->setAutoExit(false); - $application->register('dus')->setCode(function (InputInterface $input, OutputInterface $output) { + $application->register('dus')->setCode(static function (InputInterface $input, OutputInterface $output) { $output->write('dus.'); throw new \Error('duserr'); @@ -1768,7 +1764,7 @@ public function testRunWithDispatcherSkippingCommand() $application->setDispatcher($this->getDispatcher(true)); $application->setAutoExit(false); - $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output): int { + $application->register('foo')->setCode(static function (InputInterface $input, OutputInterface $output): int { $output->write('foo.'); return 0; @@ -1786,7 +1782,7 @@ public function testRunWithDispatcherAccessingInputOptions() $quietValue = null; $dispatcher = $this->getDispatcher(); - $dispatcher->addListener('console.command', function (ConsoleCommandEvent $event) use (&$noInteractionValue, &$quietValue) { + $dispatcher->addListener('console.command', static function (ConsoleCommandEvent $event) use (&$noInteractionValue, &$quietValue) { $input = $event->getInput(); $noInteractionValue = $input->getOption('no-interaction'); @@ -1797,7 +1793,7 @@ public function testRunWithDispatcherAccessingInputOptions() $application->setDispatcher($dispatcher); $application->setAutoExit(false); - $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output): int { + $application->register('foo')->setCode(static function (InputInterface $input, OutputInterface $output): int { $output->write('foo.'); return 0; @@ -1815,7 +1811,7 @@ public function testRunWithDispatcherAddingInputOptions() $extraValue = null; $dispatcher = $this->getDispatcher(); - $dispatcher->addListener('console.command', function (ConsoleCommandEvent $event) use (&$extraValue) { + $dispatcher->addListener('console.command', static function (ConsoleCommandEvent $event) use (&$extraValue) { $definition = $event->getCommand()->getDefinition(); $input = $event->getInput(); @@ -1829,7 +1825,7 @@ public function testRunWithDispatcherAddingInputOptions() $application->setDispatcher($dispatcher); $application->setAutoExit(false); - $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output): int { + $application->register('foo')->setCode(static function (InputInterface $input, OutputInterface $output): int { $output->write('foo.'); return 0; @@ -1929,7 +1925,7 @@ public function testRunLazyCommandService() public function testGetDisabledLazyCommand() { $application = new Application(); - $application->setCommandLoader(new FactoryCommandLoader(['disabled' => fn () => new DisabledCommand()])); + $application->setCommandLoader(new FactoryCommandLoader(['disabled' => static fn () => new DisabledCommand()])); $this->expectException(CommandNotFoundException::class); @@ -1939,14 +1935,14 @@ public function testGetDisabledLazyCommand() public function testHasReturnsFalseForDisabledLazyCommand() { $application = new Application(); - $application->setCommandLoader(new FactoryCommandLoader(['disabled' => fn () => new DisabledCommand()])); + $application->setCommandLoader(new FactoryCommandLoader(['disabled' => static fn () => new DisabledCommand()])); $this->assertFalse($application->has('disabled')); } public function testAllExcludesDisabledLazyCommand() { $application = new Application(); - $application->setCommandLoader(new FactoryCommandLoader(['disabled' => fn () => new DisabledCommand()])); + $application->setCommandLoader(new FactoryCommandLoader(['disabled' => static fn () => new DisabledCommand()])); $this->assertArrayNotHasKey('disabled', $application->all()); } @@ -1958,15 +1954,15 @@ public function testFindAlternativesDoesNotLoadSameNamespaceCommandsOnExactMatch $loaded = []; $application->setCommandLoader(new FactoryCommandLoader([ - 'foo:bar' => function () use (&$loaded) { + 'foo:bar' => static function () use (&$loaded) { $loaded['foo:bar'] = true; - return (new Command('foo:bar'))->setCode(function (): int { return 0; }); + return (new Command('foo:bar'))->setCode(static fn (): int => 0); }, - 'foo' => function () use (&$loaded) { + 'foo' => static function () use (&$loaded) { $loaded['foo'] = true; - return (new Command('foo'))->setCode(function (): int { return 0; }); + return (new Command('foo'))->setCode(static fn (): int => 0); }, ])); @@ -1978,21 +1974,21 @@ public function testFindAlternativesDoesNotLoadSameNamespaceCommandsOnExactMatch protected function getDispatcher($skipCommand = false) { $dispatcher = new EventDispatcher(); - $dispatcher->addListener('console.command', function (ConsoleCommandEvent $event) use ($skipCommand) { + $dispatcher->addListener('console.command', static function (ConsoleCommandEvent $event) use ($skipCommand) { $event->getOutput()->write('before.'); if ($skipCommand) { $event->disableCommand(); } }); - $dispatcher->addListener('console.terminate', function (ConsoleTerminateEvent $event) use ($skipCommand) { + $dispatcher->addListener('console.terminate', static function (ConsoleTerminateEvent $event) use ($skipCommand) { $event->getOutput()->writeln('after.'); if (!$skipCommand) { $event->setExitCode(ConsoleCommandEvent::RETURN_CODE_DISABLED); } }); - $dispatcher->addListener('console.error', function (ConsoleErrorEvent $event) { + $dispatcher->addListener('console.error', static function (ConsoleErrorEvent $event) { $event->getOutput()->write('error.'); $event->setError(new \LogicException('error.', $event->getExitCode(), $event->getError())); @@ -2007,7 +2003,7 @@ public function testErrorIsRethrownIfNotHandledByConsoleErrorEventWithCatchingEn $application->setAutoExit(false); $application->setDispatcher(new EventDispatcher()); - $application->register('dym')->setCode(function () { + $application->register('dym')->setCode(static function () { throw new \Error('Something went wrong.'); }); @@ -2024,11 +2020,11 @@ public function testErrorIsRethrownIfNotHandledByConsoleErrorEventWithCatchingEn public function testThrowingErrorListener() { $dispatcher = $this->getDispatcher(); - $dispatcher->addListener('console.error', function (ConsoleErrorEvent $event) { + $dispatcher->addListener('console.error', static function (ConsoleErrorEvent $event) { throw new \RuntimeException('foo'); }); - $dispatcher->addListener('console.command', function () { + $dispatcher->addListener('console.command', static function () { throw new \RuntimeException('bar'); }); @@ -2037,7 +2033,7 @@ public function testThrowingErrorListener() $application->setAutoExit(false); $application->setCatchExceptions(false); - $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output): int { + $application->register('foo')->setCode(static function (InputInterface $input, OutputInterface $output): int { $output->write('foo.'); return 0; @@ -2073,7 +2069,7 @@ public function testSignalListenerNotCalledByDefault() $dispatcherCalled = false; $dispatcher = new EventDispatcher(); - $dispatcher->addListener('console.signal', function () use (&$dispatcherCalled) { + $dispatcher->addListener('console.signal', static function () use (&$dispatcherCalled) { $dispatcherCalled = true; }); @@ -2091,7 +2087,7 @@ public function testSignalListener() $dispatcherCalled = false; $dispatcher = new EventDispatcher(); - $dispatcher->addListener('console.signal', function (ConsoleSignalEvent $e) use (&$dispatcherCalled) { + $dispatcher->addListener('console.signal', static function (ConsoleSignalEvent $e) use (&$dispatcherCalled) { $e->abortExit(); $dispatcherCalled = true; }); @@ -2179,7 +2175,7 @@ public function testSetSignalsToDispatchEvent() // on SIGUSR1, we need to register a blank handler to avoid the process // being stopped. $blankHandlerSignaled = false; - pcntl_signal(\SIGUSR1, function () use (&$blankHandlerSignaled) { + pcntl_signal(\SIGUSR1, static function () use (&$blankHandlerSignaled) { $blankHandlerSignaled = true; }); @@ -2273,7 +2269,7 @@ public function testSignalableWithEventCommandDoesNotInterruptedOnTermSignals() $terminateEventDispatched = false; $dispatcher = new EventDispatcher(); $dispatcher->addSubscriber($command); - $dispatcher->addListener('console.terminate', function () use (&$terminateEventDispatched) { + $dispatcher->addListener('console.terminate', static function () use (&$terminateEventDispatched) { $terminateEventDispatched = true; }); $application = new Application(); @@ -2489,7 +2485,7 @@ public function testAlarmSubscriberNotCalledForOtherSignals() #[RequiresPhpExtension('pcntl')] public function testAlarmSubscriber() { - $command = new BaseSignableCommand(signal: \SIGALRM); + $command = new BaseSignableCommand(true, \SIGALRM); $subscriber1 = new AlarmEventSubscriber(); $subscriber2 = new AlarmEventSubscriber(); @@ -2707,7 +2703,7 @@ public function testsPreservedHelpOptionWhenItsAnAlternative() #[TestWith([4])] public function testAlarmSubscriberCalledAfterSignalSubscriberAndInheritsExitCode(int|false $exitCode) { - $command = new BaseSignableCommand(signal: \SIGALRM); + $command = new BaseSignableCommand(true, \SIGALRM); $subscriber1 = new class($exitCode) extends SignalEventSubscriber { public function __construct(private int|false $exitCode) @@ -2758,7 +2754,7 @@ public function testShellVerbosityIsRestoredAfterCommandExecutionWithInitialValu $application = new Application(); $application->setAutoExit(false); $application->register('foo') - ->setCode(function (InputInterface $input, OutputInterface $output): int { + ->setCode(static function (InputInterface $input, OutputInterface $output): int { $output->write('SHELL_VERBOSITY: '.$_SERVER['SHELL_VERBOSITY']); return 0; @@ -2790,7 +2786,7 @@ public function testShellVerbosityIsRemovedAfterCommandExecutionWhenNotSetInitia $application = new Application(); $application->setAutoExit(false); $application->register('foo') - ->setCode(function (InputInterface $input, OutputInterface $output): int { + ->setCode(static function (InputInterface $input, OutputInterface $output): int { $output->write('SHELL_VERBOSITY: '.$_SERVER['SHELL_VERBOSITY']); return 0; @@ -2817,13 +2813,13 @@ public function testShellVerbosityDoesNotLeakBetweenCommandExecutions() $application = new Application(); $application->setAutoExit(false); $application->register('verbose-cmd') - ->setCode(function (InputInterface $input, OutputInterface $output): int { + ->setCode(static function (InputInterface $input, OutputInterface $output): int { $output->write('SHELL_VERBOSITY: '.$_SERVER['SHELL_VERBOSITY']); return 0; }); $application->register('normal-cmd') - ->setCode(function (InputInterface $input, OutputInterface $output): int { + ->setCode(static function (InputInterface $input, OutputInterface $output): int { $output->write('SHELL_VERBOSITY: '.$_SERVER['SHELL_VERBOSITY']); return 0; @@ -2861,7 +2857,7 @@ private function createSignalableApplication(Command $command, ?EventDispatcherI if ($dispatcher) { $application->setDispatcher($dispatcher); } - $application->addCommand(new LazyCommand($command->getName(), [], '', false, fn () => $command, true)); + $application->addCommand(new LazyCommand($command->getName(), [], '', false, static fn () => $command, true)); return $application; } diff --git a/Tests/Command/CommandTest.php b/Tests/Command/CommandTest.php index e56ddfbab..41e14a3fa 100644 --- a/Tests/Command/CommandTest.php +++ b/Tests/Command/CommandTest.php @@ -390,7 +390,7 @@ public function testRunWithProcessTitle() public function testSetCode() { $command = new \TestCommand(); - $ret = $command->setCode(function (InputInterface $input, OutputInterface $output): int { + $ret = $command->setCode(static function (InputInterface $input, OutputInterface $output): int { $output->writeln('from the code...'); return 0; @@ -550,7 +550,7 @@ public function testDeprecatedNonIntegerReturnTypeFromClosureCode() $this->expectUserDeprecationMessage('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->setCode(static function () {}); $command->run(new ArrayInput([]), new NullOutput()); } } diff --git a/Tests/Command/CompleteCommandTest.php b/Tests/Command/CompleteCommandTest.php index a1b94b773..917cb7eb5 100644 --- a/Tests/Command/CompleteCommandTest.php +++ b/Tests/Command/CompleteCommandTest.php @@ -37,7 +37,7 @@ protected function setUp(): void $this->application = new Application(); $this->application->addCommand(new CompleteCommandTest_HelloCommand()); $this->application->getDefinition() - ->addOption(new InputOption('global-option', null, InputOption::VALUE_REQUIRED, suggestedValues: ['foo', 'bar', 'baz'])); + ->addOption(new InputOption('global-option', null, InputOption::VALUE_REQUIRED, '', null, ['foo', 'bar', 'baz'])); $this->command->setApplication($this->application); $this->tester = new CommandTester($this->command); diff --git a/Tests/Command/InvokableCommandTest.php b/Tests/Command/InvokableCommandTest.php index e63c588f3..14a191eda 100644 --- a/Tests/Command/InvokableCommandTest.php +++ b/Tests/Command/InvokableCommandTest.php @@ -151,7 +151,7 @@ public function testCommandInputOptionDefinition() public function testEnumArgument() { $command = new Command('foo'); - $command->setCode(function ( + $command->setCode(static function ( #[Argument] StringEnum $enum, #[Argument] StringEnum $enumWithDefault = StringEnum::Image, #[Argument] ?StringEnum $nullableEnum = null, @@ -192,7 +192,7 @@ public function testEnumArgument() public function testEnumOption() { $command = new Command('foo'); - $command->setCode(function ( + $command->setCode(static function ( #[Option] StringEnum $enum = StringEnum::Video, #[Option] StringEnum $enumWithDefault = StringEnum::Image, #[Option] ?StringEnum $nullableEnum = null, @@ -233,7 +233,7 @@ public function testEnumOption() public function testInvalidArgumentType() { $command = new Command('foo'); - $command->setCode(function (#[Argument] object $any) {}); + $command->setCode(static function (#[Argument] object $any) {}); $this->expectException(LogicException::class); @@ -243,7 +243,7 @@ public function testInvalidArgumentType() public function testInvalidOptionType() { $command = new Command('foo'); - $command->setCode(function (#[Option] ?object $any = null) {}); + $command->setCode(static function (#[Option] ?object $any = null) {}); $this->expectException(LogicException::class); @@ -435,38 +435,38 @@ public function testInvalidOptionDefinition(callable $code) public static function provideInvalidOptionDefinitions(): \Generator { yield 'no-default' => [ - function (#[Option] string $a) {}, + static function (#[Option] string $a) {}, ]; yield 'nullable-bool-default-true' => [ - function (#[Option] ?bool $a = true) {}, + static function (#[Option] ?bool $a = true) {}, ]; yield 'nullable-bool-default-false' => [ - function (#[Option] ?bool $a = false) {}, + static function (#[Option] ?bool $a = false) {}, ]; yield 'invalid-union-type' => [ - function (#[Option] array|bool $a = false) {}, + static function (#[Option] array|bool $a = false) {}, ]; yield 'union-type-cannot-allow-null' => [ - function (#[Option] string|bool|null $a = null) {}, + static function (#[Option] string|bool|null $a = null) {}, ]; yield 'union-type-default-true' => [ - function (#[Option] string|bool $a = true) {}, + static function (#[Option] string|bool $a = true) {}, ]; yield 'union-type-default-string' => [ - function (#[Option] string|bool $a = 'foo') {}, + static function (#[Option] string|bool $a = 'foo') {}, ]; yield 'nullable-string-not-null-default' => [ - function (#[Option] ?string $a = 'foo') {}, + static function (#[Option] ?string $a = 'foo') {}, ]; yield 'nullable-array-not-null-default' => [ - function (#[Option] ?array $a = []) {}, + static function (#[Option] ?array $a = []) {}, ]; } public function testInvalidRequiredValueOptionEvenWithDefault() { $command = new Command('foo'); - $command->setCode(function (#[Option] string $a = 'a') {}); + $command->setCode(static function (#[Option] string $a = 'a') {}); $this->expectException(InvalidOptionException::class); $this->expectExceptionMessage('The "--a" option requires a value.'); diff --git a/Tests/CommandLoader/ContainerCommandLoaderTest.php b/Tests/CommandLoader/ContainerCommandLoaderTest.php index f2049ef5c..5e56228db 100644 --- a/Tests/CommandLoader/ContainerCommandLoaderTest.php +++ b/Tests/CommandLoader/ContainerCommandLoaderTest.php @@ -22,8 +22,8 @@ class ContainerCommandLoaderTest extends TestCase public function testHas() { $loader = new ContainerCommandLoader(new ServiceLocator([ - 'foo-service' => fn () => new Command('foo'), - 'bar-service' => fn () => new Command('bar'), + 'foo-service' => static fn () => new Command('foo'), + 'bar-service' => static fn () => new Command('bar'), ]), ['foo' => 'foo-service', 'bar' => 'bar-service']); $this->assertTrue($loader->has('foo')); @@ -34,8 +34,8 @@ public function testHas() public function testGet() { $loader = new ContainerCommandLoader(new ServiceLocator([ - 'foo-service' => fn () => new Command('foo'), - 'bar-service' => fn () => new Command('bar'), + 'foo-service' => static fn () => new Command('foo'), + 'bar-service' => static fn () => new Command('bar'), ]), ['foo' => 'foo-service', 'bar' => 'bar-service']); $this->assertInstanceOf(Command::class, $loader->get('foo')); @@ -51,8 +51,8 @@ public function testGetUnknownCommandThrows() public function testGetCommandNames() { $loader = new ContainerCommandLoader(new ServiceLocator([ - 'foo-service' => fn () => new Command('foo'), - 'bar-service' => fn () => new Command('bar'), + 'foo-service' => static fn () => new Command('foo'), + 'bar-service' => static fn () => new Command('bar'), ]), ['foo' => 'foo-service', 'bar' => 'bar-service']); $this->assertSame(['foo', 'bar'], $loader->getNames()); diff --git a/Tests/CommandLoader/FactoryCommandLoaderTest.php b/Tests/CommandLoader/FactoryCommandLoaderTest.php index 148806413..c12e2d132 100644 --- a/Tests/CommandLoader/FactoryCommandLoaderTest.php +++ b/Tests/CommandLoader/FactoryCommandLoaderTest.php @@ -21,8 +21,8 @@ class FactoryCommandLoaderTest extends TestCase public function testHas() { $loader = new FactoryCommandLoader([ - 'foo' => fn () => new Command('foo'), - 'bar' => fn () => new Command('bar'), + 'foo' => static fn () => new Command('foo'), + 'bar' => static fn () => new Command('bar'), ]); $this->assertTrue($loader->has('foo')); @@ -33,8 +33,8 @@ public function testHas() public function testGet() { $loader = new FactoryCommandLoader([ - 'foo' => fn () => new Command('foo'), - 'bar' => fn () => new Command('bar'), + 'foo' => static fn () => new Command('foo'), + 'bar' => static fn () => new Command('bar'), ]); $this->assertInstanceOf(Command::class, $loader->get('foo')); @@ -50,8 +50,8 @@ public function testGetUnknownCommandThrows() public function testGetCommandNames() { $loader = new FactoryCommandLoader([ - 'foo' => fn () => new Command('foo'), - 'bar' => fn () => new Command('bar'), + 'foo' => static fn () => new Command('foo'), + 'bar' => static fn () => new Command('bar'), ]); $this->assertSame(['foo', 'bar'], $loader->getNames()); diff --git a/Tests/Exception/RunCommandFailedExceptionTest.php b/Tests/Exception/RunCommandFailedExceptionTest.php index dcdfa2f48..ce8eaf97b 100644 --- a/Tests/Exception/RunCommandFailedExceptionTest.php +++ b/Tests/Exception/RunCommandFailedExceptionTest.php @@ -41,8 +41,8 @@ private static function createException(\Throwable $inner): RunCommandFailedExce $inner, new RunCommandContext( new RunCommandMessage('foo'), - exitCode: Command::FAILURE, - output: 'bar' + Command::FAILURE, + 'bar' ) ); } diff --git a/Tests/Fixtures/application_test_sigint.php b/Tests/Fixtures/application_test_sigint.php index 4a3d4eab0..f312106cf 100644 --- a/Tests/Fixtures/application_test_sigint.php +++ b/Tests/Fixtures/application_test_sigint.php @@ -18,7 +18,7 @@ (new class extends Command { protected function configure(): void { - $this->addArgument('mode', InputArgument::OPTIONAL, default: 'single'); + $this->addArgument('mode', InputArgument::OPTIONAL, '', 'single'); } protected function execute(InputInterface $input, OutputInterface $output): int diff --git a/Tests/Helper/ProcessHelperTest.php b/Tests/Helper/ProcessHelperTest.php index 298562cb8..ed05e9c25 100644 --- a/Tests/Helper/ProcessHelperTest.php +++ b/Tests/Helper/ProcessHelperTest.php @@ -90,7 +90,7 @@ public function testPassedCallbackIsExecuted() $output = $this->getOutputStream(StreamOutput::VERBOSITY_NORMAL); $executed = false; - $callback = function () use (&$executed) { $executed = true; }; + $callback = static function () use (&$executed) { $executed = true; }; $helper->run($output, ['php', '-r', 'echo 42;'], null, $callback); $this->assertTrue($executed); diff --git a/Tests/Helper/ProgressBarTest.php b/Tests/Helper/ProgressBarTest.php index 55fc04b28..abe22ba47 100644 --- a/Tests/Helper/ProgressBarTest.php +++ b/Tests/Helper/ProgressBarTest.php @@ -950,7 +950,7 @@ public function testWithSmallScreen() public function testAddingPlaceholderFormatter() { - ProgressBar::setPlaceholderFormatterDefinition('remaining_steps', fn (ProgressBar $bar) => $bar->getMaxSteps() - $bar->getProgress()); + ProgressBar::setPlaceholderFormatterDefinition('remaining_steps', static fn (ProgressBar $bar) => $bar->getMaxSteps() - $bar->getProgress()); $bar = new ProgressBar($output = $this->getOutputStream(), 3, 0); $bar->setFormat(' %remaining_steps% [%bar%]'); @@ -971,7 +971,7 @@ public function testAddingInstancePlaceholderFormatter() { $bar = new ProgressBar($output = $this->getOutputStream(), 3, 0); $bar->setFormat(' %countdown% [%bar%]'); - $bar->setPlaceholderFormatter('countdown', $function = fn (ProgressBar $bar) => $bar->getMaxSteps() - $bar->getProgress()); + $bar->setPlaceholderFormatter('countdown', $function = static fn (ProgressBar $bar) => $bar->getMaxSteps() - $bar->getProgress()); $this->assertSame($function, $bar->getPlaceholderFormatter('countdown')); @@ -1015,7 +1015,7 @@ public function testAnsiColorsAndEmojis() putenv('COLUMNS=156'); $bar = new ProgressBar($output = $this->getOutputStream(), 15, 0); - ProgressBar::setPlaceholderFormatterDefinition('memory', function (ProgressBar $bar) { + ProgressBar::setPlaceholderFormatterDefinition('memory', static function (ProgressBar $bar) { static $i = 0; $mem = 100000 * $i; $colors = $i++ ? '41;37' : '44;37'; @@ -1161,7 +1161,7 @@ public function testIterateUncountable() { $bar = new ProgressBar($output = $this->getOutputStream(), 0, 0); - $this->assertEquals([1, 2], iterator_to_array($bar->iterate((function () { + $this->assertEquals([1, 2], iterator_to_array($bar->iterate((static function () { yield 1; yield 2; })()))); diff --git a/Tests/Helper/QuestionHelperTest.php b/Tests/Helper/QuestionHelperTest.php index b55f69a91..4afa42d41 100644 --- a/Tests/Helper/QuestionHelperTest.php +++ b/Tests/Helper/QuestionHelperTest.php @@ -321,14 +321,14 @@ public function testAskWithAutocompleteCallback() // // No effort is made to avoid irrelevant suggestions, as this is handled // by the autocomplete function. - $callback = function ($input) { + $callback = static function ($input) { $knownWords = ['Carrot', 'Creme', 'Curry', 'Parsnip', 'Pie', 'Potato', 'Tart']; $inputWords = explode(' ', $input); array_pop($inputWords); $suggestionBase = $inputWords ? implode(' ', $inputWords).' ' : ''; return array_map( - fn ($word) => $suggestionBase.$word.' ', + static fn ($word) => $suggestionBase.$word.' ', $knownWords ); }; @@ -620,7 +620,7 @@ public function testAskAndValidate() $dialog->setHelperSet($helperSet); $error = 'This is not a color!'; - $validator = function ($color) use ($error) { + $validator = static function ($color) use ($error) { if (!\in_array($color, ['white', 'black'], true)) { throw new \InvalidArgumentException($error); } @@ -809,7 +809,7 @@ public function testAskThrowsExceptionOnMissingInputWithValidator() $dialog = new QuestionHelper(); $question = new Question('What\'s your name?'); - $question->setValidator(function ($value) { + $question->setValidator(static function ($value) { if (!$value) { throw new \Exception('A value is required.'); } @@ -826,7 +826,7 @@ public function testValidatorExceptionPropagatesOnEmptyInput() $dialog = new QuestionHelper(); $question = new Question('What\'s your name?'); - $question->setValidator(function ($value) { + $question->setValidator(static function ($value) { if ('' === $value || null === $value) { throw new \InvalidArgumentException('A value is required.'); } @@ -847,9 +847,9 @@ public function testQuestionValidatorRepeatsThePrompt() $application = new Application(); $application->setAutoExit(false); $application->register('question') - ->setCode(function (InputInterface $input, OutputInterface $output) use (&$tries): int { + ->setCode(static function (InputInterface $input, OutputInterface $output) use (&$tries): int { $question = new Question('This is a promptable question'); - $question->setValidator(function ($value) use (&$tries) { + $question->setValidator(static function ($value) use (&$tries) { ++$tries; if (!$value) { throw new \Exception(); diff --git a/Tests/Helper/SymfonyQuestionHelperTest.php b/Tests/Helper/SymfonyQuestionHelperTest.php index 2cafb8fe1..98fe796d3 100644 --- a/Tests/Helper/SymfonyQuestionHelperTest.php +++ b/Tests/Helper/SymfonyQuestionHelperTest.php @@ -100,7 +100,7 @@ public function testAskReturnsNullIfValidatorAllowsIt() { $questionHelper = new SymfonyQuestionHelper(); $question = new Question('What is your favorite superhero?'); - $question->setValidator(fn ($value) => $value); + $question->setValidator(static fn ($value) => $value); $input = $this->createStreamableInputInterfaceMock($this->getInputStream("\n")); $this->assertNull($questionHelper->ask($input, $this->createOutputInterface(), $question)); } diff --git a/Tests/Helper/TreeNodeTest.php b/Tests/Helper/TreeNodeTest.php index 0e80da3bd..b860e654a 100644 --- a/Tests/Helper/TreeNodeTest.php +++ b/Tests/Helper/TreeNodeTest.php @@ -56,7 +56,7 @@ public function testAddingChildrenWithGenerators() { $root = new TreeNode('Root'); - $root->addChild(function () { + $root->addChild(static function () { yield new TreeNode('Generated Child 1'); yield new TreeNode('Generated Child 2'); }); diff --git a/Tests/Input/InputArgumentTest.php b/Tests/Input/InputArgumentTest.php index a9d612f97..6802d24d2 100644 --- a/Tests/Input/InputArgumentTest.php +++ b/Tests/Input/InputArgumentTest.php @@ -121,22 +121,22 @@ public function testCompleteArray() $this->assertTrue($argument->hasCompletion()); $suggestions = new CompletionSuggestions(); $argument->complete(new CompletionInput(), $suggestions); - $this->assertSame($values, array_map(fn (Suggestion $suggestion) => $suggestion->getValue(), $suggestions->getValueSuggestions())); + $this->assertSame($values, array_map(static fn (Suggestion $suggestion) => $suggestion->getValue(), $suggestions->getValueSuggestions())); } public function testCompleteClosure() { $values = ['foo', 'bar']; - $argument = new InputArgument('foo', null, '', null, fn (CompletionInput $input): array => $values); + $argument = new InputArgument('foo', null, '', null, static fn (CompletionInput $input): array => $values); $this->assertTrue($argument->hasCompletion()); $suggestions = new CompletionSuggestions(); $argument->complete(new CompletionInput(), $suggestions); - $this->assertSame($values, array_map(fn (Suggestion $suggestion) => $suggestion->getValue(), $suggestions->getValueSuggestions())); + $this->assertSame($values, array_map(static fn (Suggestion $suggestion) => $suggestion->getValue(), $suggestions->getValueSuggestions())); } public function testCompleteClosureReturnIncorrectType() { - $argument = new InputArgument('foo', InputArgument::OPTIONAL, '', null, fn (CompletionInput $input) => 'invalid'); + $argument = new InputArgument('foo', InputArgument::OPTIONAL, '', null, static fn (CompletionInput $input) => 'invalid'); $this->expectException(LogicException::class); $this->expectExceptionMessage('Closure for argument "foo" must return an array. Got "string".'); diff --git a/Tests/Input/InputOptionTest.php b/Tests/Input/InputOptionTest.php index e5cb3318a..e70a953c4 100644 --- a/Tests/Input/InputOptionTest.php +++ b/Tests/Input/InputOptionTest.php @@ -232,22 +232,22 @@ public function testCompleteArray() $this->assertTrue($option->hasCompletion()); $suggestions = new CompletionSuggestions(); $option->complete(new CompletionInput(), $suggestions); - $this->assertSame($values, array_map(fn (Suggestion $suggestion) => $suggestion->getValue(), $suggestions->getValueSuggestions())); + $this->assertSame($values, array_map(static fn (Suggestion $suggestion) => $suggestion->getValue(), $suggestions->getValueSuggestions())); } public function testCompleteClosure() { $values = ['foo', 'bar']; - $option = new InputOption('foo', null, InputOption::VALUE_OPTIONAL, '', null, fn (CompletionInput $input): array => $values); + $option = new InputOption('foo', null, InputOption::VALUE_OPTIONAL, '', null, static fn (CompletionInput $input): array => $values); $this->assertTrue($option->hasCompletion()); $suggestions = new CompletionSuggestions(); $option->complete(new CompletionInput(), $suggestions); - $this->assertSame($values, array_map(fn (Suggestion $suggestion) => $suggestion->getValue(), $suggestions->getValueSuggestions())); + $this->assertSame($values, array_map(static fn (Suggestion $suggestion) => $suggestion->getValue(), $suggestions->getValueSuggestions())); } public function testCompleteClosureReturnIncorrectType() { - $option = new InputOption('foo', null, InputOption::VALUE_OPTIONAL, '', null, fn (CompletionInput $input) => 'invalid'); + $option = new InputOption('foo', null, InputOption::VALUE_OPTIONAL, '', null, static fn (CompletionInput $input) => 'invalid'); $this->expectException(LogicException::class); $this->expectExceptionMessage('Closure for option "foo" must return an array. Got "string".'); diff --git a/Tests/Messenger/RunCommandMessageHandlerTest.php b/Tests/Messenger/RunCommandMessageHandlerTest.php index 898492374..e2bb1ea58 100644 --- a/Tests/Messenger/RunCommandMessageHandlerTest.php +++ b/Tests/Messenger/RunCommandMessageHandlerTest.php @@ -60,7 +60,7 @@ public function testExecutesCommandThatThrowsException() public function testExecutesCommandThatCatchesThrownException() { $handler = new RunCommandMessageHandler($this->createApplicationWithCommand()); - $context = $handler(new RunCommandMessage('test:command --throw -v', throwOnFailure: false, catchExceptions: true)); + $context = $handler(new RunCommandMessage('test:command --throw -v', false, true)); $this->assertSame(1, $context->exitCode); $this->assertStringContainsString('[RuntimeException]', $context->output); diff --git a/Tests/Question/QuestionTest.php b/Tests/Question/QuestionTest.php index 0fc26aed1..20e9a8f7e 100644 --- a/Tests/Question/QuestionTest.php +++ b/Tests/Question/QuestionTest.php @@ -60,7 +60,7 @@ public function testIsHiddenDefault() public function testSetHiddenWithAutocompleterCallback() { $this->question->setAutocompleterCallback( - fn (string $input): array => [] + static fn (string $input): array => [] ); $this->expectException(\LogicException::class); @@ -74,7 +74,7 @@ public function testSetHiddenWithAutocompleterCallback() public function testSetHiddenWithNoAutocompleterCallback() { $this->question->setAutocompleterCallback( - fn (string $input): array => [] + static fn (string $input): array => [] ); $this->question->setAutocompleterCallback(null); @@ -179,7 +179,7 @@ public function testGetAutocompleterValuesDefault() public function testGetSetAutocompleterCallback() { - $callback = fn (string $input): array => []; + $callback = static fn (string $input): array => []; $this->question->setAutocompleterCallback($callback); self::assertSame($callback, $this->question->getAutocompleterCallback()); @@ -200,7 +200,7 @@ public function testSetAutocompleterCallbackWhenHidden() ); $this->question->setAutocompleterCallback( - fn (string $input): array => [] + static fn (string $input): array => [] ); } @@ -212,7 +212,7 @@ public function testSetAutocompleterCallbackWhenNotHidden() $exception = null; try { $this->question->setAutocompleterCallback( - fn (string $input): array => [] + static fn (string $input): array => [] ); } catch (\Exception $exception) { // Do nothing @@ -224,7 +224,7 @@ public function testSetAutocompleterCallbackWhenNotHidden() public static function providerGetSetValidator() { return [ - [fn ($input) => $input], + [static fn ($input) => $input], [null], ]; } @@ -274,7 +274,7 @@ public function testGetMaxAttemptsDefault() public function testGetSetNormalizer() { - $normalizer = fn ($input) => $input; + $normalizer = static fn ($input) => $input; $this->question->setNormalizer($normalizer); self::assertSame($normalizer, $this->question->getNormalizer()); } diff --git a/Tests/SignalRegistry/SignalRegistryTest.php b/Tests/SignalRegistry/SignalRegistryTest.php index 46796fb99..2431f83c8 100644 --- a/Tests/SignalRegistry/SignalRegistryTest.php +++ b/Tests/SignalRegistry/SignalRegistryTest.php @@ -34,7 +34,7 @@ public function testOneCallbackForASignalSignalIsHandled() $signalRegistry = new SignalRegistry(); $isHandled = false; - $signalRegistry->register(\SIGUSR1, function () use (&$isHandled) { + $signalRegistry->register(\SIGUSR1, static function () use (&$isHandled) { $isHandled = true; }); @@ -48,12 +48,12 @@ public function testTwoCallbacksForASignalBothCallbacksAreCalled() $signalRegistry = new SignalRegistry(); $isHandled1 = false; - $signalRegistry->register(\SIGUSR1, function () use (&$isHandled1) { + $signalRegistry->register(\SIGUSR1, static function () use (&$isHandled1) { $isHandled1 = true; }); $isHandled2 = false; - $signalRegistry->register(\SIGUSR1, function () use (&$isHandled2) { + $signalRegistry->register(\SIGUSR1, static function () use (&$isHandled2) { $isHandled2 = true; }); @@ -70,7 +70,7 @@ public function testTwoSignalsSignalsAreHandled() $isHandled1 = false; $isHandled2 = false; - $signalRegistry->register(\SIGUSR1, function () use (&$isHandled1) { + $signalRegistry->register(\SIGUSR1, static function () use (&$isHandled1) { $isHandled1 = true; }); @@ -79,7 +79,7 @@ public function testTwoSignalsSignalsAreHandled() $this->assertTrue($isHandled1); $this->assertFalse($isHandled2); - $signalRegistry->register(\SIGUSR2, function () use (&$isHandled2) { + $signalRegistry->register(\SIGUSR2, static function () use (&$isHandled2) { $isHandled2 = true; }); @@ -93,12 +93,12 @@ public function testTwoCallbacksForASignalPreviousAndRegisteredCallbacksWereCall $signalRegistry = new SignalRegistry(); $isHandled1 = false; - pcntl_signal(\SIGUSR1, function () use (&$isHandled1) { + pcntl_signal(\SIGUSR1, static function () use (&$isHandled1) { $isHandled1 = true; }); $isHandled2 = false; - $signalRegistry->register(\SIGUSR1, function () use (&$isHandled2) { + $signalRegistry->register(\SIGUSR1, static function () use (&$isHandled2) { $isHandled2 = true; }); @@ -113,14 +113,14 @@ public function testTwoCallbacksForASignalPreviousCallbackFromAnotherRegistry() $signalRegistry1 = new SignalRegistry(); $isHandled1 = false; - $signalRegistry1->register(\SIGUSR1, function () use (&$isHandled1) { + $signalRegistry1->register(\SIGUSR1, static function () use (&$isHandled1) { $isHandled1 = true; }); $signalRegistry2 = new SignalRegistry(); $isHandled2 = false; - $signalRegistry2->register(\SIGUSR1, function () use (&$isHandled2) { + $signalRegistry2->register(\SIGUSR1, static function () use (&$isHandled2) { $isHandled2 = true; }); diff --git a/Tests/Tester/ApplicationTesterTest.php b/Tests/Tester/ApplicationTesterTest.php index 24fc392bd..b67e127dc 100644 --- a/Tests/Tester/ApplicationTesterTest.php +++ b/Tests/Tester/ApplicationTesterTest.php @@ -32,7 +32,7 @@ protected function setUp(): void $this->application->setAutoExit(false); $this->application->register('foo') ->addArgument('foo') - ->setCode(function (OutputInterface $output): int { + ->setCode(static function (OutputInterface $output): int { $output->writeln('foo'); return 0; @@ -70,7 +70,7 @@ public function testSetInputs() { $application = new Application(); $application->setAutoExit(false); - $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output): int { + $application->register('foo')->setCode(static function (InputInterface $input, OutputInterface $output): int { $helper = new QuestionHelper(); $helper->ask($input, $output, new Question('Q1')); $helper->ask($input, $output, new Question('Q2')); @@ -140,7 +140,7 @@ public function testErrorOutput() $application->setAutoExit(false); $application->register('foo') ->addArgument('foo') - ->setCode(function (OutputInterface $output): int { + ->setCode(static function (OutputInterface $output): int { $output->getErrorOutput()->write('foo'); return 0; diff --git a/Tests/Tester/CommandTesterTest.php b/Tests/Tester/CommandTesterTest.php index dd46dbb02..4bc2256e8 100644 --- a/Tests/Tester/CommandTesterTest.php +++ b/Tests/Tester/CommandTesterTest.php @@ -42,7 +42,7 @@ protected function setUp(): void $this->command = new Command('foo'); $this->command->addArgument('command'); $this->command->addArgument('foo'); - $this->command->setCode(function (OutputInterface $output): int { + $this->command->setCode(static function (OutputInterface $output): int { $output->writeln('foo'); return 0; @@ -106,7 +106,7 @@ public function testCommandFromApplication() $application->setAutoExit(false); $command = new Command('foo'); - $command->setCode(function (OutputInterface $output): int { + $command->setCode(static function (OutputInterface $output): int { $output->writeln('foo'); return 0; @@ -130,7 +130,7 @@ public function testCommandWithInputs() $command = new Command('foo'); $command->setHelperSet(new HelperSet([new QuestionHelper()])); - $command->setCode(function (InputInterface $input, OutputInterface $output) use ($questions, $command): int { + $command->setCode(static 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])); @@ -153,7 +153,7 @@ public function testCommandWithMultilineInputs() $command = new Command('foo'); $command->setHelperSet(new HelperSet([new QuestionHelper()])); - $command->setCode(function (InputInterface $input, OutputInterface $output) use ($question, $command): int { + $command->setCode(static function (InputInterface $input, OutputInterface $output) use ($question, $command): int { $output->write($command->getHelper('question')->ask($input, $output, (new Question($question))->setMultiline(true))); $output->write(stream_get_contents($input->getStream())); @@ -183,7 +183,7 @@ public function testCommandWithDefaultInputs() $command = new Command('foo'); $command->setHelperSet(new HelperSet([new QuestionHelper()])); - $command->setCode(function (InputInterface $input, OutputInterface $output) use ($questions, $command): int { + $command->setCode(static 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')); @@ -210,7 +210,7 @@ public function testCommandWithWrongInputsNumber() $command = new Command('foo'); $command->setHelperSet(new HelperSet([new QuestionHelper()])); - $command->setCode(function (InputInterface $input, OutputInterface $output) use ($questions, $command): int { + $command->setCode(static 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])); @@ -239,7 +239,7 @@ public function testCommandWithQuestionsButNoInputs() $command = new Command('foo'); $command->setHelperSet(new HelperSet([new QuestionHelper()])); - $command->setCode(function (InputInterface $input, OutputInterface $output) use ($questions, $command): int { + $command->setCode(static 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])); @@ -266,7 +266,7 @@ public function testSymfonyStyleCommandWithInputs() ]; $command = new Command('foo'); - $command->setCode(function (InputInterface $input, OutputInterface $output) use ($questions): int { + $command->setCode(static function (InputInterface $input, OutputInterface $output) use ($questions): int { $io = new SymfonyStyle($input, $output); $io->ask($questions[0]); $io->ask($questions[1]); @@ -287,7 +287,7 @@ public function testErrorOutput() $command = new Command('foo'); $command->addArgument('command'); $command->addArgument('foo'); - $command->setCode(function (OutputInterface $output): int { + $command->setCode(static function (OutputInterface $output): int { $output->getErrorOutput()->write('foo'); return 0; diff --git a/phpunit.xml.dist b/phpunit.xml.dist index a3dd340ba..792e75dba 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,7 +1,7 @@ - + trigger_deprecation Doctrine\Deprecations\Deprecation::trigger Doctrine\Deprecations\Deprecation::triggerIfCalledFromOutside