|
19 | 19 | namespace FastForward\DevTools\Tests\Console\Command; |
20 | 20 |
|
21 | 21 | use FastForward\DevTools\Console\Command\ReportsCommand; |
| 22 | +use FastForward\DevTools\Process\ProcessBuilderInterface; |
| 23 | +use FastForward\DevTools\Process\ProcessQueueInterface; |
22 | 24 | use PHPUnit\Framework\Attributes\CoversClass; |
23 | 25 | use PHPUnit\Framework\Attributes\Test; |
| 26 | +use PHPUnit\Framework\TestCase; |
24 | 27 | use Prophecy\Argument; |
25 | 28 | use Prophecy\PhpUnit\ProphecyTrait; |
| 29 | +use Prophecy\Prophecy\ObjectProphecy; |
| 30 | +use ReflectionMethod; |
| 31 | +use Symfony\Component\Console\Input\InputInterface; |
| 32 | +use Symfony\Component\Console\Output\OutputInterface; |
| 33 | +use Symfony\Component\Process\Process; |
26 | 34 |
|
27 | 35 | #[CoversClass(ReportsCommand::class)] |
28 | | -final class ReportsCommandTest extends AbstractCommandTestCase |
| 36 | +final class ReportsCommandTest extends TestCase |
29 | 37 | { |
30 | 38 | use ProphecyTrait; |
31 | 39 |
|
32 | | - /** |
33 | | - * @return string |
34 | | - */ |
35 | | - protected function getCommandClass(): string |
36 | | - { |
37 | | - return ReportsCommand::class; |
38 | | - } |
| 40 | + /** @var ObjectProphecy<ProcessBuilderInterface> */ |
| 41 | + private ObjectProphecy $processBuilder; |
| 42 | + |
| 43 | + /** @var ObjectProphecy<ProcessQueueInterface> */ |
| 44 | + private ObjectProphecy $processQueue; |
| 45 | + |
| 46 | + /** @var ObjectProphecy<InputInterface> */ |
| 47 | + private ObjectProphecy $input; |
| 48 | + |
| 49 | + /** @var ObjectProphecy<OutputInterface> */ |
| 50 | + private ObjectProphecy $output; |
| 51 | + |
| 52 | + /** @var ObjectProphecy<Process> */ |
| 53 | + private ObjectProphecy $docsProcess; |
| 54 | + |
| 55 | + /** @var ObjectProphecy<Process> */ |
| 56 | + private ObjectProphecy $testsProcess; |
39 | 57 |
|
40 | | - /** |
41 | | - * @return string |
42 | | - */ |
43 | | - protected function getCommandName(): string |
| 58 | + private ReportsCommand $command; |
| 59 | + |
| 60 | + protected function setUp(): void |
44 | 61 | { |
45 | | - return 'reports'; |
| 62 | + $this->processBuilder = $this->prophesize(ProcessBuilderInterface::class); |
| 63 | + $this->processQueue = $this->prophesize(ProcessQueueInterface::class); |
| 64 | + $this->input = $this->prophesize(InputInterface::class); |
| 65 | + $this->output = $this->prophesize(OutputInterface::class); |
| 66 | + $this->docsProcess = $this->prophesize(Process::class); |
| 67 | + $this->testsProcess = $this->prophesize(Process::class); |
| 68 | + |
| 69 | + $this->input->getOption('target')->willReturn('public'); |
| 70 | + $this->input->getOption('coverage')->willReturn('public/coverage'); |
| 71 | + |
| 72 | + $this->processBuilder->withArgument(Argument::cetera()) |
| 73 | + ->willReturn($this->processBuilder->reveal()); |
| 74 | + |
| 75 | + $this->processBuilder->build('composer dev-tools docs') |
| 76 | + ->willReturn($this->docsProcess->reveal()); |
| 77 | + |
| 78 | + $this->processBuilder->build('composer dev-tools tests') |
| 79 | + ->willReturn($this->testsProcess->reveal()); |
| 80 | + |
| 81 | + $this->processQueue->run($this->output->reveal()) |
| 82 | + ->willReturn(ReportsCommand::SUCCESS); |
| 83 | + |
| 84 | + $this->command = new ReportsCommand( |
| 85 | + $this->processBuilder->reveal(), |
| 86 | + $this->processQueue->reveal() |
| 87 | + ); |
46 | 88 | } |
47 | 89 |
|
48 | | - /** |
49 | | - * @return string |
50 | | - */ |
51 | | - protected function getCommandDescription(): string |
| 90 | + #[Test] |
| 91 | + public function commandWillSetExpectedNameDescriptionAndHelp(): void |
52 | 92 | { |
53 | | - return 'Generates the frontpage for Fast Forward documentation.'; |
| 93 | + self::assertSame('reports', $this->command->getName()); |
| 94 | + self::assertSame('Generates the frontpage for Fast Forward documentation.', $this->command->getDescription()); |
| 95 | + self::assertSame('This command generates the frontpage for Fast Forward documentation, including links to API documentation and test reports.', $this->command->getHelp()); |
54 | 96 | } |
55 | 97 |
|
56 | | - /** |
57 | | - * @return string |
58 | | - */ |
59 | | - protected function getCommandHelp(): string |
| 98 | + #[Test] |
| 99 | + public function commandWillHaveExpectedOptions(): void |
60 | 100 | { |
61 | | - return 'This command generates the frontpage for Fast Forward documentation, including links to API documentation and test reports.'; |
| 101 | + $definition = $this->command->getDefinition(); |
| 102 | + |
| 103 | + self::assertTrue($definition->hasOption('target')); |
| 104 | + self::assertTrue($definition->hasOption('coverage')); |
62 | 105 | } |
63 | 106 |
|
64 | | - /** |
65 | | - * @return void |
66 | | - */ |
67 | 107 | #[Test] |
68 | | - public function executeWillRunDocsAndTestsCommand(): void |
| 108 | + public function executeWillRunDocsAndTestsCommandAsDetachedProcesses(): void |
69 | 109 | { |
70 | 110 | $this->output->writeln('<info>Generating frontpage for Fast Forward documentation...</info>') |
71 | | - ->shouldBeCalled(); |
72 | | - $this->output->writeln(Argument::containingString('Generating API documentation on path:')) |
73 | | - ->shouldBeCalled(); |
74 | | - $this->output->writeln(Argument::containingString('Generating test coverage report on path:')) |
75 | | - ->shouldBeCalled(); |
| 111 | + ->shouldBeCalledOnce(); |
| 112 | + |
| 113 | + $this->processBuilder->withArgument('--ansi') |
| 114 | + ->shouldBeCalled() |
| 115 | + ->willReturn($this->processBuilder->reveal()); |
| 116 | + |
| 117 | + $this->processBuilder->withArgument('--target', 'public') |
| 118 | + ->shouldBeCalledOnce() |
| 119 | + ->willReturn($this->processBuilder->reveal()); |
| 120 | + |
| 121 | + $this->processBuilder->withArgument('--coverage', 'public/coverage') |
| 122 | + ->shouldBeCalledOnce() |
| 123 | + ->willReturn($this->processBuilder->reveal()); |
| 124 | + |
| 125 | + $this->processQueue->add($this->docsProcess->reveal(), false, true) |
| 126 | + ->shouldBeCalledOnce(); |
| 127 | + |
| 128 | + $this->processQueue->add($this->testsProcess->reveal(), false, true) |
| 129 | + ->shouldBeCalledOnce(); |
| 130 | + |
| 131 | + $result = $this->executeCommand(); |
| 132 | + |
| 133 | + self::assertSame(ReportsCommand::SUCCESS, $result); |
| 134 | + } |
| 135 | + |
| 136 | + private function executeCommand(): int |
| 137 | + { |
| 138 | + $reflectionMethod = new ReflectionMethod($this->command, 'execute'); |
76 | 139 |
|
77 | | - self::assertSame(ReportsCommand::SUCCESS, $this->invokeExecute()); |
| 140 | + return $reflectionMethod->invoke($this->command, $this->input->reveal(), $this->output->reveal()); |
78 | 141 | } |
79 | 142 | } |
0 commit comments