-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
94 additions
and
1 deletion.
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,51 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
use Contributte\Console\Application; | ||
use Contributte\Console\DI\ConsoleExtension; | ||
use Nette\DI\Compiler; | ||
use Nette\DI\Container; | ||
use Nette\DI\ContainerLoader; | ||
use Symfony\Component\Console\ConsoleEvents; | ||
use Symfony\Component\Console\Event\ConsoleErrorEvent; | ||
use Symfony\Component\Console\Input\ArrayInput; | ||
use Symfony\Component\Console\Output\NullOutput; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
use Tester\Assert; | ||
use Tester\FileMock; | ||
use Tests\Fixtures\ThrowingCommand; | ||
|
||
require_once __DIR__ . '/../../../bootstrap.php'; | ||
|
||
test(function (): void { | ||
$loader = new ContainerLoader(TEMP_DIR, true); | ||
$class = $loader->load(function (Compiler $compiler): void { | ||
$compiler->addExtension('console', new ConsoleExtension(true)); | ||
$compiler->loadConfig(FileMock::create(' | ||
services: | ||
- Tests\Fixtures\ThrowingCommand | ||
- Symfony\Component\EventDispatcher\EventDispatcher | ||
', 'neon')); | ||
}, [getmypid(), 1]); | ||
|
||
/** @var Container $container */ | ||
$container = new $class(); | ||
|
||
/** @var Application $application */ | ||
$application = $container->getByType(Application::class); | ||
Assert::type(Application::class, $container->getByType(Application::class)); | ||
|
||
/** @var EventDispatcherInterface $dispatcher */ | ||
$dispatcher = $container->getByType(EventDispatcherInterface::class); | ||
$dispatcher->addListener(ConsoleEvents::ERROR, function (ConsoleErrorEvent $event): void { | ||
Assert::same(ThrowingCommand::ERROR_MESSAGE, $event->getError()->getMessage()); | ||
}); | ||
|
||
Assert::exception(function () use ($application): void { | ||
$application->doRun( | ||
new ArrayInput([ | ||
'command' => 'throwing', | ||
]), | ||
new NullOutput() | ||
); | ||
}, Throwable::class, ThrowingCommand::ERROR_MESSAGE); | ||
}); |
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,31 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Tests\Fixtures; | ||
|
||
use Exception; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
final class ThrowingCommand extends Command | ||
{ | ||
|
||
/** @var string */ | ||
protected static $defaultName = 'throwing'; | ||
|
||
public const ERROR_MESSAGE = 'I am internally broken.'; | ||
|
||
/** | ||
* Configure command | ||
*/ | ||
protected function configure(): void | ||
{ | ||
$this->setName(self::$defaultName); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): void | ||
{ | ||
throw new Exception(self::ERROR_MESSAGE); | ||
} | ||
|
||
} |