|
1 | 1 | <?php
|
2 | 2 |
|
| 3 | +namespace Inhere\ConsoleTest; |
| 4 | + |
| 5 | +use Inhere\Console\Application; |
3 | 6 | use Inhere\Console\IO\InputInterface;
|
4 |
| -use Inhere\Console\IO\OutputInterface; |
5 | 7 | use PHPUnit\Framework\TestCase;
|
6 |
| -use Inhere\Console\Application; |
7 | 8 |
|
8 | 9 | /**
|
9 | 10 | * @covers Application
|
10 | 11 | */
|
11 | 12 | class ApplicationTest extends TestCase
|
12 | 13 | {
|
| 14 | + private function newApp() |
| 15 | + { |
| 16 | + return new Application([ |
| 17 | + 'name' => 'Tests', |
| 18 | + 'debug' => 1, |
| 19 | + 'version' => '1.0.0', |
| 20 | + ]); |
| 21 | + } |
| 22 | + |
13 | 23 | public function testApp()
|
14 | 24 | {
|
15 | 25 | $app = new Application([
|
16 |
| - 'name' => 'Tests', |
17 |
| - 'debug' => 1, |
| 26 | + 'name' => 'Tests', |
| 27 | + 'debug' => 1, |
18 | 28 | 'version' => '1.0.0',
|
19 | 29 | ]);
|
20 | 30 |
|
21 | 31 | $this->assertArrayHasKey('name', $app->getMeta());
|
| 32 | + $this->assertEquals('Tests', $app->getName()); |
22 | 33 | $this->assertEquals('Tests', $app->getMeta('name'));
|
23 | 34 |
|
24 | 35 | $this->assertInstanceOf(InputInterface::class, $app->getInput());
|
25 |
| - $this->assertInstanceOf(OutputInterface::class, $app->getOutput()); |
| 36 | + } |
| 37 | + |
| 38 | + public function testAddCommand() |
| 39 | + { |
| 40 | + $app = $this->newApp(); |
| 41 | + |
| 42 | + $app->addCommand('test', function (){ |
| 43 | + return 0; |
| 44 | + }); |
| 45 | + |
| 46 | + $this->assertTrue($app->isCommand('test')); |
| 47 | + $this->assertFalse($app->isController('test')); |
| 48 | + $this->assertArrayHasKey('test', $app->getCommands()); |
| 49 | + $this->assertContains('test', $app->getCommandNames()); |
| 50 | + } |
| 51 | + |
| 52 | + public function testAddController() |
| 53 | + { |
| 54 | + $app = $this->newApp(); |
| 55 | + |
| 56 | + $app->addGroup('test', TestController::class); |
| 57 | + |
| 58 | + $this->assertTrue($app->isController('test')); |
| 59 | + $this->assertFalse($app->isCommand('test')); |
| 60 | + $this->assertArrayHasKey('test', $app->getControllers()); |
| 61 | + $this->assertContains('test', $app->getControllerNames()); |
| 62 | + $this->assertSame(TestController::class, $app->getControllers()['test']); |
| 63 | + } |
| 64 | + |
| 65 | + public function testAddControllerError() |
| 66 | + { |
| 67 | + $app = $this->newApp(); |
| 68 | + |
| 69 | + $this->expectException(\InvalidArgumentException::class); |
| 70 | + $this->expectExceptionMessageRegExp('/"name" and "controller" cannot be empty/'); |
| 71 | + $app->addController(''); |
| 72 | + |
| 73 | + $this->expectException(\InvalidArgumentException::class); |
| 74 | + $this->expectExceptionMessageRegExp('/"name" and "controller" cannot be empty/'); |
| 75 | + $app->controller('test', 'invalid'); |
26 | 76 | }
|
27 | 77 | }
|
0 commit comments