1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace GacelaTest\Unit\Console\Domain\FileContent; |
6
|
|
|
|
7
|
|
|
use Gacela\Console\Domain\CommandArguments\CommandArguments; |
8
|
|
|
use Gacela\Console\Domain\FileContent\FileContentGenerator; |
9
|
|
|
use Gacela\Console\Domain\FileContent\FileContentIoInterface; |
10
|
|
|
use Gacela\Console\Domain\FilenameSanitizer\FilenameSanitizer; |
11
|
|
|
use PHPUnit\Framework\TestCase; |
12
|
|
|
|
13
|
|
|
final class FileContentGeneratorTest extends TestCase |
14
|
|
|
{ |
15
|
|
|
public function test_error_when_unknown_template(): void |
16
|
|
|
{ |
17
|
|
|
$fileContentIo = $this->createStub(FileContentIoInterface::class); |
18
|
|
|
$generator = new FileContentGenerator($fileContentIo, []); |
19
|
|
|
|
20
|
|
|
$this->expectExceptionMessage("Unknown template for 'unknown_template'?"); |
21
|
|
|
$generator->generate( |
22
|
|
|
new CommandArguments('Namespace', 'Dir'), |
23
|
|
|
'unknown_template', |
24
|
|
|
); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function test_facade_maker_template(): void |
28
|
|
|
{ |
29
|
|
|
$fileContentIo = $this->createMock(FileContentIoInterface::class); |
30
|
|
|
$fileContentIo->expects(self::once()) |
31
|
|
|
->method('mkdir') |
32
|
|
|
->with('Dir'); |
33
|
|
|
|
34
|
|
|
$fileContentIo->expects(self::once()) |
35
|
|
|
->method('filePutContents') |
36
|
|
|
->with('Dir/DirFacade.php', 'template-result'); |
37
|
|
|
|
38
|
|
|
$generator = new FileContentGenerator($fileContentIo, [ |
39
|
|
|
'Facade' => 'template-result', |
40
|
|
|
]); |
41
|
|
|
|
42
|
|
|
$actualPath = $generator->generate( |
43
|
|
|
new CommandArguments('Namespace', 'Dir'), |
44
|
|
|
FilenameSanitizer::FACADE, |
45
|
|
|
); |
46
|
|
|
|
47
|
|
|
self::assertSame('Dir/DirFacade.php', $actualPath); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function test_factory_maker_template(): void |
51
|
|
|
{ |
52
|
|
|
$fileContentIo = $this->createMock(FileContentIoInterface::class); |
53
|
|
|
$fileContentIo->expects(self::once()) |
54
|
|
|
->method('mkdir') |
55
|
|
|
->with('Dir'); |
56
|
|
|
|
57
|
|
|
$fileContentIo->expects(self::once()) |
58
|
|
|
->method('filePutContents') |
59
|
|
|
->with('Dir/DirFactory.php', 'template-result'); |
60
|
|
|
|
61
|
|
|
$generator = new FileContentGenerator($fileContentIo, [ |
62
|
|
|
'Factory' => 'template-result', |
63
|
|
|
]); |
64
|
|
|
|
65
|
|
|
$actualPath = $generator->generate( |
66
|
|
|
new CommandArguments('Namespace', 'Dir'), |
67
|
|
|
FilenameSanitizer::FACTORY, |
68
|
|
|
); |
69
|
|
|
|
70
|
|
|
self::assertSame('Dir/DirFactory.php', $actualPath); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function test_config_maker_template(): void |
74
|
|
|
{ |
75
|
|
|
$fileContentIo = $this->createMock(FileContentIoInterface::class); |
76
|
|
|
$fileContentIo->expects(self::once()) |
77
|
|
|
->method('mkdir') |
78
|
|
|
->with('Dir'); |
79
|
|
|
|
80
|
|
|
$fileContentIo->expects(self::once()) |
81
|
|
|
->method('filePutContents') |
82
|
|
|
->with('Dir/DirConfig.php', 'template-result'); |
83
|
|
|
|
84
|
|
|
$generator = new FileContentGenerator($fileContentIo, [ |
85
|
|
|
'Config' => 'template-result', |
86
|
|
|
]); |
87
|
|
|
|
88
|
|
|
$actualPath = $generator->generate( |
89
|
|
|
new CommandArguments('Namespace', 'Dir'), |
90
|
|
|
FilenameSanitizer::CONFIG, |
91
|
|
|
); |
92
|
|
|
|
93
|
|
|
self::assertSame('Dir/DirConfig.php', $actualPath); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function test_dependency_provider_maker_template(): void |
97
|
|
|
{ |
98
|
|
|
$fileContentIo = $this->createMock(FileContentIoInterface::class); |
99
|
|
|
$fileContentIo->expects(self::once()) |
100
|
|
|
->method('mkdir') |
101
|
|
|
->with('Dir'); |
102
|
|
|
|
103
|
|
|
$fileContentIo->expects(self::once()) |
104
|
|
|
->method('filePutContents') |
105
|
|
|
->with('Dir/DirDependencyProvider.php', 'template-result'); |
106
|
|
|
|
107
|
|
|
$generator = new FileContentGenerator($fileContentIo, [ |
108
|
|
|
'DependencyProvider' => 'template-result', |
109
|
|
|
]); |
110
|
|
|
|
111
|
|
|
$actualPath = $generator->generate( |
112
|
|
|
new CommandArguments('Namespace', 'Dir'), |
113
|
|
|
FilenameSanitizer::DEPENDENCY_PROVIDER, |
114
|
|
|
); |
115
|
|
|
|
116
|
|
|
self::assertSame('Dir/DirDependencyProvider.php', $actualPath); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|