Skip to content

Commit

Permalink
Merge pull request #81 from sunrise-php/release/v2.11.1
Browse files Browse the repository at this point in the history
v2.11.1
  • Loading branch information
fenric authored Oct 12, 2021
2 parents fc35ef3 + 1913417 commit f1764a2
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 15 deletions.
3 changes: 3 additions & 0 deletions src/Command/RouteListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ public function __construct(?Router $router = null)
{
parent::__construct();

$this->setName(static::$defaultName);
$this->setDescription(static::$defaultDescription);

$this->router = $router;
}

Expand Down
60 changes: 45 additions & 15 deletions tests/Command/RouteListCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,43 +32,73 @@ public function testRun() : void
]);

$command = new RouteListCommand($router);
$commandTester = new CommandTester($command);

$exitCode = $commandTester->execute([]);
$this->assertSame('router:route-list', $command->getName());

$commandTester = new CommandTester($command);

$this->assertSame(0, $exitCode);
$this->assertSame(0, $commandTester->execute([]));
}

/**
* @return void
*/
public function testRunWithoutRouter() : void
public function testRunInheritedCommand() : void
{
$command = new RouteListCommand();
$commandTester = new CommandTester($command);
$command = new class extends RouteListCommand
{
public function __construct()
{
parent::__construct(null);
}

$this->expectException(RuntimeException::class);
protected function getRouter() : Router
{
return new Router();
}
};

$commandTester->execute([]);
$this->assertSame('router:route-list', $command->getName());

$commandTester = new CommandTester($command);

$this->assertSame(0, $commandTester->execute([]));
}

/**
* @return void
*/
public function testRunInheritedCommand() : void
public function testRunRenamedCommand() : void
{
$userCommand = new class extends RouteListCommand
$command = new class extends RouteListCommand
{
protected function getRouter() : Router
protected static $defaultName = 'foo';
protected static $defaultDescription = 'bar';

public function __construct()
{
return new Router();
parent::__construct(new Router());
}
};

$commandTester = new CommandTester($userCommand);
$this->assertSame('foo', $command->getName());
$this->assertSame('bar', $command->getDescription());

$exitCode = $commandTester->execute([]);
$commandTester = new CommandTester($command);

$this->assertSame(0, $commandTester->execute([]));
}

$this->assertSame(0, $exitCode);
/**
* @return void
*/
public function testRunWithoutRouter() : void
{
$command = new RouteListCommand();
$commandTester = new CommandTester($command);

$this->expectException(RuntimeException::class);

$commandTester->execute([]);
}
}

0 comments on commit f1764a2

Please sign in to comment.