|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace ApiGen\Tests\Generator; |
|
4
|
|
|
|
|
5
|
|
|
use ApiGen\Contracts\Console\Helper\ProgressBarInterface; |
|
6
|
|
|
use ApiGen\Contracts\Generator\StepCounterInterface; |
|
7
|
|
|
use ApiGen\Contracts\Generator\TemplateGenerators\ConditionalTemplateGeneratorInterface; |
|
8
|
|
|
use ApiGen\Contracts\Generator\TemplateGenerators\TemplateGeneratorInterface; |
|
9
|
|
|
use ApiGen\Generator\GeneratorQueue; |
|
10
|
|
|
use ApiGen\Tests\MethodInvoker; |
|
11
|
|
|
use PHPUnit\Framework\TestCase; |
|
12
|
|
|
|
|
13
|
|
|
final class GeneratorQueueTest extends TestCase |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var GeneratorQueue |
|
17
|
|
|
*/ |
|
18
|
|
|
private $generatorQueue; |
|
19
|
|
|
|
|
20
|
|
|
protected function setUp(): void |
|
21
|
|
|
{ |
|
22
|
|
|
$progressBarMock = $this->createMock(ProgressBarInterface::class); |
|
23
|
|
|
$this->generatorQueue = new GeneratorQueue($progressBarMock); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function testRun(): void |
|
27
|
|
|
{ |
|
28
|
|
|
$this->assertFileNotExists(TEMP_DIR . '/file.txt'); |
|
29
|
|
|
|
|
30
|
|
|
$templateGeneratorMock = $this->createMock(TemplateGeneratorInterface::class); |
|
31
|
|
|
$templateGeneratorMock->method('generate') |
|
32
|
|
|
->willReturn(file_put_contents(TEMP_DIR . '/file.txt', '...')); |
|
33
|
|
|
$this->generatorQueue->addToQueue($templateGeneratorMock); |
|
34
|
|
|
$this->generatorQueue->run(); |
|
35
|
|
|
|
|
36
|
|
|
$this->assertFileExists(TEMP_DIR . '/file.txt'); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function testGetAllowedQueue(): void |
|
40
|
|
|
{ |
|
41
|
|
|
$this->generatorQueue->addToQueue($this->createConditionalTemplateGenerator()); |
|
42
|
|
|
|
|
43
|
|
|
$this->assertCount(0, MethodInvoker::callMethodOnObject($this->generatorQueue, 'getAllowedQueue')); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function testGetStepCount(): void |
|
47
|
|
|
{ |
|
48
|
|
|
$templateGeneratorMock = $this->createMock([TemplateGeneratorInterface::class, StepCounterInterface::class]); |
|
49
|
|
|
$templateGeneratorMock->method('getStepCount') |
|
50
|
|
|
->willReturn(50); |
|
51
|
|
|
$this->generatorQueue->addToQueue($templateGeneratorMock); |
|
52
|
|
|
|
|
53
|
|
|
$this->assertSame(50, MethodInvoker::callMethodOnObject($this->generatorQueue, 'getStepCount')); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
private function createConditionalTemplateGenerator(): ConditionalTemplateGeneratorInterface |
|
57
|
|
|
{ |
|
58
|
|
|
return new class implements ConditionalTemplateGeneratorInterface |
|
59
|
|
|
{ |
|
60
|
|
|
public function isAllowed(): bool |
|
61
|
|
|
{ |
|
62
|
|
|
return false; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function generate(): void |
|
66
|
|
|
{ |
|
67
|
|
|
} |
|
68
|
|
|
}; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|