Passed
Push — main ( 4c5dd6...a4db54 )
by Chema
03:49 queued 13s
created

test_dependency_provider_maker_template_with_short_name()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 14
nc 1
nop 0
dl 0
loc 22
rs 9.7998
c 1
b 0
f 0
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_facade_maker_template_with_short_name(): 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/Facade.php', 'template-result');
60
61
        $generator = new FileContentGenerator($fileContentIo, [
62
            'Facade' => 'template-result',
63
        ]);
64
65
        $actualPath = $generator->generate(
66
            new CommandArguments('Namespace', 'Dir'),
67
            FilenameSanitizer::FACADE,
68
            withShortName: true,
69
        );
70
71
        self::assertSame('Dir/Facade.php', $actualPath);
72
    }
73
74
    public function test_factory_maker_template(): void
75
    {
76
        $fileContentIo = $this->createMock(FileContentIoInterface::class);
77
        $fileContentIo->expects(self::once())
78
            ->method('mkdir')
79
            ->with('Dir');
80
81
        $fileContentIo->expects(self::once())
82
            ->method('filePutContents')
83
            ->with('Dir/DirFactory.php', 'template-result');
84
85
        $generator = new FileContentGenerator($fileContentIo, [
86
            'Factory' => 'template-result',
87
        ]);
88
89
        $actualPath = $generator->generate(
90
            new CommandArguments('Namespace', 'Dir'),
91
            FilenameSanitizer::FACTORY,
92
        );
93
94
        self::assertSame('Dir/DirFactory.php', $actualPath);
95
    }
96
97
    public function test_factory_maker_template_with_short_name(): void
98
    {
99
        $fileContentIo = $this->createMock(FileContentIoInterface::class);
100
        $fileContentIo->expects(self::once())
101
            ->method('mkdir')
102
            ->with('Dir');
103
104
        $fileContentIo->expects(self::once())
105
            ->method('filePutContents')
106
            ->with('Dir/Factory.php', 'template-result');
107
108
        $generator = new FileContentGenerator($fileContentIo, [
109
            'Factory' => 'template-result',
110
        ]);
111
112
        $actualPath = $generator->generate(
113
            new CommandArguments('Namespace', 'Dir'),
114
            FilenameSanitizer::FACTORY,
115
            withShortName: true,
116
        );
117
118
        self::assertSame('Dir/Factory.php', $actualPath);
119
    }
120
121
    public function test_config_maker_template(): void
122
    {
123
        $fileContentIo = $this->createMock(FileContentIoInterface::class);
124
        $fileContentIo->expects(self::once())
125
            ->method('mkdir')
126
            ->with('Dir');
127
128
        $fileContentIo->expects(self::once())
129
            ->method('filePutContents')
130
            ->with('Dir/DirConfig.php', 'template-result');
131
132
        $generator = new FileContentGenerator($fileContentIo, [
133
            'Config' => 'template-result',
134
        ]);
135
136
        $actualPath = $generator->generate(
137
            new CommandArguments('Namespace', 'Dir'),
138
            FilenameSanitizer::CONFIG,
139
        );
140
141
        self::assertSame('Dir/DirConfig.php', $actualPath);
142
    }
143
144
    public function test_config_maker_template_with_short_name(): void
145
    {
146
        $fileContentIo = $this->createMock(FileContentIoInterface::class);
147
        $fileContentIo->expects(self::once())
148
            ->method('mkdir')
149
            ->with('Dir');
150
151
        $fileContentIo->expects(self::once())
152
            ->method('filePutContents')
153
            ->with('Dir/Config.php', 'template-result');
154
155
        $generator = new FileContentGenerator($fileContentIo, [
156
            'Config' => 'template-result',
157
        ]);
158
159
        $actualPath = $generator->generate(
160
            new CommandArguments('Namespace', 'Dir'),
161
            FilenameSanitizer::CONFIG,
162
            withShortName: true,
163
        );
164
165
        self::assertSame('Dir/Config.php', $actualPath);
166
    }
167
168
    public function test_dependency_provider_maker_template(): void
169
    {
170
        $fileContentIo = $this->createMock(FileContentIoInterface::class);
171
        $fileContentIo->expects(self::once())
172
            ->method('mkdir')
173
            ->with('Dir');
174
175
        $fileContentIo->expects(self::once())
176
            ->method('filePutContents')
177
            ->with('Dir/DirDependencyProvider.php', 'template-result');
178
179
        $generator = new FileContentGenerator($fileContentIo, [
180
            'DependencyProvider' => 'template-result',
181
        ]);
182
183
        $actualPath = $generator->generate(
184
            new CommandArguments('Namespace', 'Dir'),
185
            FilenameSanitizer::DEPENDENCY_PROVIDER,
186
        );
187
188
        self::assertSame('Dir/DirDependencyProvider.php', $actualPath);
189
    }
190
191
    public function test_dependency_provider_maker_template_with_short_name(): void
192
    {
193
        $fileContentIo = $this->createMock(FileContentIoInterface::class);
194
        $fileContentIo->expects(self::once())
195
            ->method('mkdir')
196
            ->with('Dir');
197
198
        $fileContentIo->expects(self::once())
199
            ->method('filePutContents')
200
            ->with('Dir/DependencyProvider.php', 'template-result');
201
202
        $generator = new FileContentGenerator($fileContentIo, [
203
            'DependencyProvider' => 'template-result',
204
        ]);
205
206
        $actualPath = $generator->generate(
207
            new CommandArguments('Namespace', 'Dir'),
208
            FilenameSanitizer::DEPENDENCY_PROVIDER,
209
            withShortName: true,
210
        );
211
212
        self::assertSame('Dir/DependencyProvider.php', $actualPath);
213
    }
214
}
215