Skip to content

Commit e1288d3

Browse files
committed
[Console] Simplify using invokable commands when the component is used standalone
1 parent b55991c commit e1288d3

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

Tests/Command/DebugCommandTest.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,12 @@ public function testComplete(array $input, array $expectedSuggestions)
304304
$environment = new Environment($loader);
305305

306306
$application = new Application();
307-
$application->add(new DebugCommand($environment, $projectDir, [], null, null));
307+
$command = new DebugCommand($environment, $projectDir, [], null, null);
308+
if (method_exists($application, 'addCommand')) {
309+
$application->addCommand($command);
310+
} else {
311+
$application->add($command);
312+
}
308313

309314
$tester = new CommandCompletionTester($application->find('debug:twig'));
310315
$suggestions = $tester->complete($input, 2);
@@ -339,7 +344,12 @@ private function createCommandTester(array $paths = [], array $bundleMetadata =
339344
}
340345

341346
$application = new Application();
342-
$application->add(new DebugCommand($environment, $projectDir, $bundleMetadata, $defaultPath, null));
347+
$command = new DebugCommand($environment, $projectDir, $bundleMetadata, $defaultPath, null);
348+
if (method_exists($application, 'addCommand')) {
349+
$application->addCommand($command);
350+
} else {
351+
$application->add($command);
352+
}
343353
$command = $application->find('debug:twig');
344354

345355
return new CommandTester($command);

Tests/Command/LintCommandTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,11 @@ private function createCommand(): Command
179179
$command = new LintCommand($environment);
180180

181181
$application = new Application();
182-
$application->add($command);
182+
if (method_exists($application, 'addCommand')) {
183+
$application->addCommand($command);
184+
} else {
185+
$application->add($command);
186+
}
183187

184188
return $application->find('lint:twig');
185189
}

0 commit comments

Comments
 (0)