Skip to content

Commit

Permalink
Separate chain calls (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
sankaest committed Jun 1, 2022
1 parent 4be703b commit 56bbaba
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 21 deletions.
4 changes: 3 additions & 1 deletion src/Application.php
Expand Up @@ -82,7 +82,9 @@ protected function doRenderThrowable(Throwable $e, OutputInterface $output): voi

public function addOptions(InputOption $options): void
{
$this->getDefinition()->addOption($options);
$this
->getDefinition()
->addOption($options);
}

public function extractNamespace(string $name, int $limit = null): string
Expand Down
24 changes: 18 additions & 6 deletions tests/ApplicationTest.php
Expand Up @@ -15,7 +15,9 @@ public function testDispatcherEventApplicationStartup(): void
{
$event = new ApplicationStartup();

$result = $this->getInaccessibleProperty($this->application(), 'dispatcher')->dispatch($event);
$result = $this
->getInaccessibleProperty($this->application(), 'dispatcher')
->dispatch($event);

$this->assertSame($event, $result);
}
Expand All @@ -24,15 +26,19 @@ public function testDispatcherEventApplicationShutdown(): void
{
$event = new ApplicationShutdown(ExitCode::OK);

$result = $this->getInaccessibleProperty($this->application(), 'dispatcher')->dispatch($event);
$result = $this
->getInaccessibleProperty($this->application(), 'dispatcher')
->dispatch($event);

$this->assertSame($event, $result);
$this->assertEquals(ExitCode::OK, $event->getExitCode());
}

public function testDoRenderThrowable(): void
{
$command = $this->application()->find('stub');
$command = $this
->application()
->find('stub');

$commandCreate = new CommandTester($command);

Expand Down Expand Up @@ -63,7 +69,9 @@ public function testDoRenderThrowable(): void

public function testDoRenderThrowableWithStyledOutput(): void
{
$command = $this->application()->find('stub');
$command = $this
->application()
->find('stub');

$commandCreate = new CommandTester($command);

Expand Down Expand Up @@ -92,7 +100,9 @@ public function testDoRenderThrowableWithStyledOutput(): void

public function testRenamedCommand(): void
{
$command = $this->application()->find('stub/rename');
$command = $this
->application()
->find('stub/rename');

$commandCreate = new CommandTester($command);

Expand Down Expand Up @@ -122,6 +132,8 @@ public function namespaceProvider(): array
*/
public function testExtractNamespace(string $name, ?int $limit, string $expected): void
{
$this->assertSame($expected, $this->application()->extractNamespace($name, $limit));
$this->assertSame($expected, $this
->application()
->extractNamespace($name, $limit));
}
}
26 changes: 20 additions & 6 deletions tests/CommandLoaderTest.php
Expand Up @@ -26,7 +26,9 @@ protected function setUp(): void
{
parent::setUp();

$this->loader = $this->container()->get(CommandLoaderInterface::class);
$this->loader = $this
->container()
->get(CommandLoaderInterface::class);
}

public function testGetNames(): void
Expand All @@ -36,10 +38,18 @@ public function testGetNames(): void

public function testGetAlias(): void
{
$this->assertSame([], $this->loader->get('serve')->getAliases());
$this->assertSame(['st'], $this->loader->get('st')->getAliases());
$this->assertSame(['st'], $this->loader->get('stub')->getAliases());
$this->assertSame([], $this->loader->get('stub/rename')->getAliases());
$this->assertSame([], $this->loader
->get('serve')
->getAliases());
$this->assertSame(['st'], $this->loader
->get('st')
->getAliases());
$this->assertSame(['st'], $this->loader
->get('stub')
->getAliases());
$this->assertSame([], $this->loader
->get('stub/rename')
->getAliases());
}

public function testGetThrowExceptionIfCommandDoesNotExist(): void
Expand Down Expand Up @@ -71,7 +81,11 @@ public function testConstructThrowExceptionIfItIsNotPossibleToCreateCommandObjec
$loader = new CommandLoader(
new SimpleContainer([], static function () {
$reflection = new ReflectionClass(ErrorCommand::class);
$definition = $reflection->getConstructor()->getParameters()[0]->getType()->getName();
$definition = $reflection
->getConstructor()
->getParameters()[0]
->getType()
->getName();

if (class_exists($definition)) {
return $reflection->newInstanceArgs(new $definition());
Expand Down
4 changes: 3 additions & 1 deletion tests/ErrorListenerTest.php
Expand Up @@ -18,7 +18,9 @@ public function testOnError()
$logger = new SimpleLogger();
$errorListener = new ErrorListener($logger);

$command = $this->application()->find('serve');
$command = $this
->application()
->find('serve');

$consoleErrorEvent = new ConsoleErrorEvent(
new ArrayInput([]),
Expand Down
24 changes: 18 additions & 6 deletions tests/ServeCommandTest.php
Expand Up @@ -13,7 +13,9 @@ final class ServeCommandTest extends TestCase
{
public function testServeCommandExecuteWithoutArguments(): void
{
$command = $this->application()->find('serve');
$command = $this
->application()
->find('serve');

$commandCreate = new CommandTester($command);

Expand All @@ -36,7 +38,9 @@ public function testServeCommandExecuteWithoutArguments(): void

public function testServeCommandExecuteWithDocRoot(): void
{
$command = $this->application()->find('serve');
$command = $this
->application()
->find('serve');

$commandCreate = new CommandTester($command);

Expand Down Expand Up @@ -69,7 +73,9 @@ public function testServeCommandExecuteWithDocRoot(): void

public function testErrorWhenAddressIsTaken(): void
{
$command = $this->application()->find('serve');
$command = $this
->application()
->find('serve');

$commandCreate = new CommandTester($command);

Expand Down Expand Up @@ -112,7 +118,9 @@ public function testErrorWhenAddressIsTaken(): void

public function testErrorWhenRouterDoesNotExist(): void
{
$command = $this->application()->find('serve');
$command = $this
->application()
->find('serve');

$commandCreate = new CommandTester($command);

Expand All @@ -136,7 +144,9 @@ public function testErrorWhenRouterDoesNotExist(): void

public function testSuccess(): void
{
$command = $this->application()->find('serve');
$command = $this
->application()
->find('serve');

$commandCreate = new CommandTester($command);

Expand Down Expand Up @@ -168,7 +178,9 @@ public function testSuccess(): void
*/
public function testAutocompletion(array $input, array $suggestions): void
{
$command = $this->application()->find('serve');
$command = $this
->application()
->find('serve');

$commandTester = new CommandCompletionTester($command);

Expand Down
4 changes: 3 additions & 1 deletion tests/TestCase.php
Expand Up @@ -48,7 +48,9 @@ protected function container(): ContainerInterface

protected function application(): Application
{
return $this->container()->get(Application::class);
return $this
->container()
->get(Application::class);
}

/**
Expand Down

0 comments on commit 56bbaba

Please sign in to comment.