From cd742252968516d223d35f13437ed90fe5918bae Mon Sep 17 00:00:00 2001 From: Massimiliano Arione Date: Tue, 2 Dec 2025 08:36:27 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20allow=20testing=20of=20new=20com?= =?UTF-8?q?mands?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phpstan-baseline.neon | 6 ------ src/Test/WebTestCase.php | 26 +++++++++++++++++--------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 6582b45..e69de29 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,6 +0,0 @@ -parameters: - ignoreErrors: - - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeDefinition\\:\\:children\\(\\)\\.$#" - count: 1 - path: src/DependencyInjection/Configuration.php diff --git a/src/Test/WebTestCase.php b/src/Test/WebTestCase.php index 9681bd4..9ebc0fa 100644 --- a/src/Test/WebTestCase.php +++ b/src/Test/WebTestCase.php @@ -150,23 +150,31 @@ protected static function ajax(string $method, string $uri, array $params = [], /** * Execute a command and return output. * - * @param string $name Command name (e.g. "app:send") - * @param Command $command Command instance (e.g. new SendCommand()) - * @param array $arguments Possible command arguments and options - * @param array $otherCommands Possible other commands to define - * @param ?array $inputs Possible inputs to set inside command + * @param string $name Command name (e.g. "app:send") + * @param callable|object $command Command instance (e.g. new SendCommand()) + * @param array $arguments Possible command arguments and options + * @param array $otherCommands Possible other commands to define + * @param ?array $inputs Possible inputs to set inside command */ protected static function commandTest( string $name, - Command $command, + callable|object $command, array $arguments = [], array $otherCommands = [], ?array $inputs = null, ): string { $application = new Application(self::$client->getKernel()); - $application->add($command); - foreach ($otherCommands as $otherCommand) { - $application->add($otherCommand); + // @phpstan-ignore-next-line function.alreadyNarrowedType + if (\method_exists($application, 'addCommand')) { + $application->addCommand($command); + foreach ($otherCommands as $otherCommand) { + $application->addCommand($otherCommand); + } + } else { + $application->add($command); + foreach ($otherCommands as $otherCommand) { + $application->add($otherCommand); + } } $cmd = $application->find($name); $commandTester = new CommandTester($cmd);