Skip to content

Commit 6921c1e

Browse files
authored
Merge pull request #37 from Bee-Lab/enhance-command-test
🎨 allow testing of new commands
2 parents b1659cd + cd74225 commit 6921c1e

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +0,0 @@
1-
parameters:
2-
ignoreErrors:
3-
-
4-
message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeDefinition\\:\\:children\\(\\)\\.$#"
5-
count: 1
6-
path: src/DependencyInjection/Configuration.php

src/Test/WebTestCase.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,23 +150,31 @@ protected static function ajax(string $method, string $uri, array $params = [],
150150
/**
151151
* Execute a command and return output.
152152
*
153-
* @param string $name Command name (e.g. "app:send")
154-
* @param Command $command Command instance (e.g. new SendCommand())
155-
* @param array $arguments Possible command arguments and options
156-
* @param array $otherCommands Possible other commands to define
157-
* @param ?array $inputs Possible inputs to set inside command
153+
* @param string $name Command name (e.g. "app:send")
154+
* @param callable|object $command Command instance (e.g. new SendCommand())
155+
* @param array $arguments Possible command arguments and options
156+
* @param array $otherCommands Possible other commands to define
157+
* @param ?array $inputs Possible inputs to set inside command
158158
*/
159159
protected static function commandTest(
160160
string $name,
161-
Command $command,
161+
callable|object $command,
162162
array $arguments = [],
163163
array $otherCommands = [],
164164
?array $inputs = null,
165165
): string {
166166
$application = new Application(self::$client->getKernel());
167-
$application->add($command);
168-
foreach ($otherCommands as $otherCommand) {
169-
$application->add($otherCommand);
167+
// @phpstan-ignore-next-line function.alreadyNarrowedType
168+
if (\method_exists($application, 'addCommand')) {
169+
$application->addCommand($command);
170+
foreach ($otherCommands as $otherCommand) {
171+
$application->addCommand($otherCommand);
172+
}
173+
} else {
174+
$application->add($command);
175+
foreach ($otherCommands as $otherCommand) {
176+
$application->add($otherCommand);
177+
}
170178
}
171179
$cmd = $application->find($name);
172180
$commandTester = new CommandTester($cmd);

0 commit comments

Comments
 (0)