1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace ApiGen\Tests\Console\Command; |
4
|
|
|
|
5
|
|
|
use ApiGen\Console\Command\GenerateCommand; |
6
|
|
|
use ApiGen\Tests\AbstractContainerAwareTestCase; |
7
|
|
|
use ApiGen\Tests\MethodInvoker; |
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
9
|
|
|
use Symfony\Component\Console\Output\ConsoleOutput; |
10
|
|
|
use Symfony\Component\Console\Output\NullOutput; |
11
|
|
|
use Symfony\Component\Console\Output\Output; |
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
13
|
|
|
|
14
|
|
|
final class GenerateCommandExecuteTest extends AbstractContainerAwareTestCase |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var GenerateCommand |
18
|
|
|
*/ |
19
|
|
|
private $generateCommand; |
20
|
|
|
|
21
|
|
|
protected function setUp(): void |
22
|
|
|
{ |
23
|
|
|
$this->generateCommand = $this->container->getByType(GenerateCommand::class); |
24
|
|
|
|
25
|
|
|
/** @var ConsoleOutput $output */ |
26
|
|
|
$output = $this->container->getByType(OutputInterface::class); |
27
|
|
|
$output->setVerbosity(Output::VERBOSITY_QUIET); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testExecute(): void |
31
|
|
|
{ |
32
|
|
|
$this->assertFileNotExists(TEMP_DIR . '/api/index.html'); |
33
|
|
|
|
34
|
|
|
$inputMock = $this->createMock(InputInterface::class); |
35
|
|
|
$inputMock->method('getArgument')->willReturn([ |
36
|
|
|
__DIR__ . '/Source' |
37
|
|
|
]); |
38
|
|
|
$inputMock->method('getOptions')->willReturn([ |
39
|
|
|
'config' => null, |
40
|
|
|
'destination' => TEMP_DIR . '/api', |
41
|
|
|
'source' => __DIR__ . '/Source' |
42
|
|
|
]); |
43
|
|
|
$outputMock = $this->createMock(OutputInterface::class); |
44
|
|
|
|
45
|
|
|
$this->assertSame( |
46
|
|
|
0, // success |
47
|
|
|
MethodInvoker::callMethodOnObject( |
48
|
|
|
$this->generateCommand, |
49
|
|
|
'execute', |
50
|
|
|
[$inputMock, $outputMock] |
51
|
|
|
) |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
$this->assertFileExists(TEMP_DIR . '/api/index.html'); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @expectedException \ApiGen\Configuration\Exceptions\ConfigurationException |
59
|
|
|
*/ |
60
|
|
|
public function testExecuteWithError(): void |
61
|
|
|
{ |
62
|
|
|
$inputMock = $this->createMock(InputInterface::class); |
63
|
|
|
$inputMock->method('getArgument')->willReturn([ |
64
|
|
|
__DIR__ |
65
|
|
|
]); |
66
|
|
|
$inputMock->method('getOptions')->willReturn([ |
67
|
|
|
'config' => null |
68
|
|
|
]); |
69
|
|
|
|
70
|
|
|
MethodInvoker::callMethodOnObject( |
71
|
|
|
$this->generateCommand, |
72
|
|
|
'execute', |
73
|
|
|
[$inputMock, new NullOutput()] |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|