-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ConsoleExtension: support command tags in NEON (#76)
- Loading branch information
1 parent
e52267a
commit dc2b84f
Showing
4 changed files
with
110 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
use Contributte\Console\Application; | ||
use Contributte\Console\DI\ConsoleExtension; | ||
use Contributte\Tester\Toolkit; | ||
use Contributte\Tester\Utils\ContainerBuilder; | ||
use Contributte\Tester\Utils\Neonkit; | ||
use Nette\DI\Compiler; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Exception\CommandNotFoundException; | ||
use Tester\Assert; | ||
|
||
require_once __DIR__ . '/../../bootstrap.php'; | ||
|
||
// console.command | ||
Toolkit::test(function (): void { | ||
$container = ContainerBuilder::of() | ||
->withCompiler(function (Compiler $compiler): void { | ||
$compiler->addExtension('console', new ConsoleExtension(true)); | ||
$compiler->addConfig(Neonkit::load(<<<'NEON' | ||
console: | ||
services: | ||
foo: | ||
class: Tests\Fixtures\FooCommand | ||
tags: [console.command: app:foo] | ||
bar: | ||
class: Tests\Fixtures\BarCommand | ||
tags: [console.command: {name: app:bar}] | ||
NEON | ||
)); | ||
})->build(); | ||
|
||
$application = $container->getByType(Application::class); | ||
assert($application instanceof Application); | ||
|
||
Assert::count(2, $container->findByType(Command::class)); | ||
Assert::same(['help', 'list', '_complete', 'completion', 'app:foo', 'app:bar'], array_keys($application->all())); | ||
}); | ||
|
||
// try to set command other name | ||
Toolkit::test(function (): void { | ||
$container = ContainerBuilder::of() | ||
->withCompiler(function (Compiler $compiler): void { | ||
$compiler->addExtension('console', new ConsoleExtension(true)); | ||
$compiler->addConfig(Neonkit::load(<<<'NEON' | ||
console: | ||
services: | ||
foo: | ||
class: Tests\Fixtures\FooCommand | ||
tags: [console.command: fake] | ||
NEON | ||
)); | ||
})->build(); | ||
|
||
$application = $container->getByType(Application::class); | ||
assert($application instanceof Application); | ||
|
||
Assert::exception( | ||
fn () => $application->all(), | ||
CommandNotFoundException::class, | ||
'The "fake" command cannot be found because it is registered under multiple names. Make sure you don\'t set a different name via constructor or "setName()".' | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Tests\Fixtures; | ||
|
||
use Symfony\Component\Console\Attribute\AsCommand; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
#[AsCommand( | ||
name: 'app:bar', | ||
description: 'Bar command', | ||
)] | ||
final class BarCommand extends Command | ||
{ | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
return 0; | ||
} | ||
|
||
} |