From 113d52fa8295c74e5011ba5de652376687723790 Mon Sep 17 00:00:00 2001 From: Anatoly Nekhay Date: Tue, 12 Oct 2021 18:16:44 +0500 Subject: [PATCH 1/2] improve command --- src/Command/RouteListCommand.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Command/RouteListCommand.php b/src/Command/RouteListCommand.php index 275bb02c..090a97d7 100644 --- a/src/Command/RouteListCommand.php +++ b/src/Command/RouteListCommand.php @@ -66,6 +66,9 @@ public function __construct(?Router $router = null) { parent::__construct(); + $this->setName(static::$defaultName); + $this->setDescription(static::$defaultDescription); + $this->router = $router; } From 19134177bc53bf1271b5c2af3bc0a43a66213128 Mon Sep 17 00:00:00 2001 From: Anatoly Nekhay Date: Tue, 12 Oct 2021 18:16:58 +0500 Subject: [PATCH 2/2] improve tests --- tests/Command/RouteListCommandTest.php | 60 +++++++++++++++++++------- 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/tests/Command/RouteListCommandTest.php b/tests/Command/RouteListCommandTest.php index a4e13f6d..deab9ebf 100644 --- a/tests/Command/RouteListCommandTest.php +++ b/tests/Command/RouteListCommandTest.php @@ -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([]); } }