|
5 | 5 | namespace Hyde\Framework\Testing\Unit;
|
6 | 6 |
|
7 | 7 | use Hyde\Testing\TestCase;
|
| 8 | +use Hyde\Console\Commands\ServeCommand; |
8 | 9 |
|
9 | 10 | /**
|
10 | 11 | * @covers \Hyde\Console\Commands\ServeCommand
|
|
13 | 14 | */
|
14 | 15 | class ServeCommandOptionsUnitTest extends TestCase
|
15 | 16 | {
|
16 |
| - // |
| 17 | + public function test_getHostSelection() |
| 18 | + { |
| 19 | + $command = new ServeCommandMock(); |
| 20 | + $this->assertSame('localhost', $command->getHostSelection()); |
| 21 | + } |
| 22 | + |
| 23 | + public function test_getHostSelection_withHostOption() |
| 24 | + { |
| 25 | + $command = new ServeCommandMock(['host' => 'foo']); |
| 26 | + $this->assertSame('foo', $command->getHostSelection()); |
| 27 | + } |
| 28 | + |
| 29 | + public function test_getHostSelection_withConfigOption() |
| 30 | + { |
| 31 | + $this->app['config']->set('hyde.server.host', 'foo'); |
| 32 | + $command = new ServeCommandMock(); |
| 33 | + $this->assertSame('foo', $command->getHostSelection()); |
| 34 | + } |
| 35 | + |
| 36 | + public function test_getHostSelection_withHostOptionAndConfigOption() |
| 37 | + { |
| 38 | + $this->app['config']->set('hyde.server.host', 'foo'); |
| 39 | + $command = new ServeCommandMock(['host' => 'bar']); |
| 40 | + $this->assertSame('bar', $command->getHostSelection()); |
| 41 | + } |
| 42 | + |
| 43 | + public function test_getPortSelection() |
| 44 | + { |
| 45 | + $command = new ServeCommandMock(); |
| 46 | + $this->assertSame(8080, $command->getPortSelection()); |
| 47 | + } |
| 48 | + |
| 49 | + public function test_getPortSelection_withPortOption() |
| 50 | + { |
| 51 | + $command = new ServeCommandMock(['port' => 8081]); |
| 52 | + $this->assertSame(8081, $command->getPortSelection()); |
| 53 | + } |
| 54 | + |
| 55 | + public function test_getPortSelection_withConfigOption() |
| 56 | + { |
| 57 | + $this->app['config']->set('hyde.server.port', 8082); |
| 58 | + $command = new ServeCommandMock(); |
| 59 | + $this->assertSame(8082, $command->getPortSelection()); |
| 60 | + } |
| 61 | + |
| 62 | + public function test_getPortSelection_withPortOptionAndConfigOption() |
| 63 | + { |
| 64 | + $this->app['config']->set('hyde.server.port', 8082); |
| 65 | + $command = new ServeCommandMock(['port' => 8081]); |
| 66 | + $this->assertSame(8081, $command->getPortSelection()); |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +/** |
| 71 | + * @method getHostSelection |
| 72 | + * @method getPortSelection |
| 73 | + */ |
| 74 | +class ServeCommandMock extends ServeCommand |
| 75 | +{ |
| 76 | + public function __construct(array $options = []) |
| 77 | + { |
| 78 | + parent::__construct(); |
| 79 | + |
| 80 | + $this->input = new InputMock($options); |
| 81 | + } |
| 82 | + |
| 83 | + public function __call($method, $parameters) |
| 84 | + { |
| 85 | + return call_user_func_array([$this, $method], $parameters); |
| 86 | + } |
| 87 | + |
| 88 | + public function option($key = null) |
| 89 | + { |
| 90 | + return $this->input->getOption($key); |
| 91 | + } |
| 92 | +} |
| 93 | + |
| 94 | +class InputMock { |
| 95 | + protected array $options; |
| 96 | + |
| 97 | + public function __construct(array $options = []) |
| 98 | + { |
| 99 | + $this->options = $options; |
| 100 | + } |
| 101 | + |
| 102 | + public function getOption(string $key) |
| 103 | + { |
| 104 | + return $this->options[$key] ?? null; |
| 105 | + } |
17 | 106 | }
|
0 commit comments