|
5 | 5 | use Laravel\Boost\Contracts\Agent; |
6 | 6 | use Laravel\Boost\Install\GuidelineWriter; |
7 | 7 |
|
8 | | -test('it returns early when guidelines are empty', function () { |
| 8 | +test('it returns NOOP when guidelines are empty', function () { |
9 | 9 | $agent = Mockery::mock(Agent::class); |
10 | 10 | $agent->shouldReceive('guidelinesPath')->andReturn('/tmp/test.md'); |
11 | 11 |
|
12 | 12 | $writer = new GuidelineWriter($agent); |
13 | 13 |
|
14 | | - // Should not throw any exception |
15 | | - $writer->write(''); |
| 14 | + $result = $writer->write(''); |
| 15 | + expect($result)->toBe(GuidelineWriter::NOOP); |
16 | 16 | }); |
17 | 17 |
|
18 | 18 | test('it creates directory when it does not exist', function () { |
|
60 | 60 | $writer->write('test guidelines content'); |
61 | 61 |
|
62 | 62 | $content = file_get_contents($tempFile); |
63 | | - expect($content)->toBe("\n\n\n<laravel-boost-guidelines>\ntest guidelines content\n</laravel-boost-guidelines>"); |
| 63 | + expect($content)->toBe("<laravel-boost-guidelines>\ntest guidelines content\n</laravel-boost-guidelines>"); |
64 | 64 |
|
65 | 65 | unlink($tempFile); |
66 | 66 | }); |
|
77 | 77 | $writer->write('new guidelines'); |
78 | 78 |
|
79 | 79 | $content = file_get_contents($tempFile); |
80 | | - expect($content)->toBe("# Existing content\n\nSome text here.\n\n\n<laravel-boost-guidelines>\nnew guidelines\n</laravel-boost-guidelines>"); |
| 80 | + expect($content)->toBe("# Existing content\n\nSome text here.\n\n===\n\n<laravel-boost-guidelines>\nnew guidelines\n</laravel-boost-guidelines>"); |
81 | 81 |
|
82 | 82 | unlink($tempFile); |
83 | 83 | }); |
|
165 | 165 | $writer->write('my guidelines'); |
166 | 166 |
|
167 | 167 | $content = file_get_contents($tempFile); |
168 | | - expect($content)->toBe("# Title\n\nParagraph 1\n\nParagraph 2\n\n\n<laravel-boost-guidelines>\nmy guidelines\n</laravel-boost-guidelines>"); |
| 168 | + expect($content)->toBe("# Title\n\nParagraph 1\n\nParagraph 2\n\n===\n\n<laravel-boost-guidelines>\nmy guidelines\n</laravel-boost-guidelines>"); |
169 | 169 |
|
170 | 170 | unlink($tempFile); |
171 | 171 | }); |
|
182 | 182 | $writer->write('first guidelines'); |
183 | 183 |
|
184 | 184 | $content = file_get_contents($tempFile); |
185 | | - expect($content)->toBe("\n\n\n<laravel-boost-guidelines>\nfirst guidelines\n</laravel-boost-guidelines>"); |
| 185 | + expect($content)->toBe("<laravel-boost-guidelines>\nfirst guidelines\n</laravel-boost-guidelines>"); |
186 | 186 |
|
187 | 187 | unlink($tempFile); |
188 | 188 | }); |
|
199 | 199 | $writer->write('clean guidelines'); |
200 | 200 |
|
201 | 201 | $content = file_get_contents($tempFile); |
202 | | - expect($content)->toBe("\n\n\n<laravel-boost-guidelines>\nclean guidelines\n</laravel-boost-guidelines>"); |
| 202 | + expect($content)->toBe("<laravel-boost-guidelines>\nclean guidelines\n</laravel-boost-guidelines>"); |
203 | 203 |
|
204 | 204 | unlink($tempFile); |
205 | 205 | }); |
|
214 | 214 | $agent->shouldReceive('frontmatter')->andReturn(false); |
215 | 215 |
|
216 | 216 | $writer = new GuidelineWriter($agent); |
217 | | - $writer->write('new guidelines'); |
| 217 | + $result = $writer->write('new guidelines'); |
218 | 218 |
|
| 219 | + expect($result)->toBe(GuidelineWriter::REPLACED); |
219 | 220 | $content = file_get_contents($tempFile); |
220 | 221 | expect($content)->toBe("# Title\n\n<other-rules>\nShould not be touched\n</other-rules>\n\n<laravel-boost-guidelines>\nnew guidelines\n</laravel-boost-guidelines>\n\n<custom-config>\nAlso untouched\n</custom-config>"); |
221 | 222 |
|
|
295 | 296 | $writer->write('new guidelines'); |
296 | 297 |
|
297 | 298 | $content = file_get_contents($tempFile); |
298 | | - expect($content)->toBe("---\nalwaysApply: true\n---\n# Existing content\n\nSome text here.\n\n\n<laravel-boost-guidelines>\nnew guidelines\n</laravel-boost-guidelines>"); |
| 299 | + expect($content)->toBe("---\nalwaysApply: true\n---\n# Existing content\n\nSome text here.\n\n===\n\n<laravel-boost-guidelines>\nnew guidelines\n</laravel-boost-guidelines>"); |
299 | 300 |
|
300 | 301 | unlink($tempFile); |
301 | 302 | }); |
|
312 | 313 | $writer->write('new guidelines'); |
313 | 314 |
|
314 | 315 | $content = file_get_contents($tempFile); |
315 | | - expect($content)->toBe("---\ncustomOption: true\n---\n# Existing content\n\nSome text here.\n\n\n<laravel-boost-guidelines>\nnew guidelines\n</laravel-boost-guidelines>"); |
| 316 | + expect($content)->toBe("---\ncustomOption: true\n---\n# Existing content\n\nSome text here.\n\n===\n\n<laravel-boost-guidelines>\nnew guidelines\n</laravel-boost-guidelines>"); |
316 | 317 |
|
317 | 318 | unlink($tempFile); |
318 | 319 | }); |
|
326 | 327 | $agent->shouldReceive('frontmatter')->andReturn(false); |
327 | 328 |
|
328 | 329 | $writer = new GuidelineWriter($agent); |
329 | | - $writer->write('new guidelines'); |
| 330 | + $result = $writer->write('new guidelines'); |
330 | 331 |
|
| 332 | + expect($result)->toBe(GuidelineWriter::NEW); |
331 | 333 | $content = file_get_contents($tempFile); |
332 | | - expect($content)->toBe("# Existing content\n\nSome text here.\n\n\n<laravel-boost-guidelines>\nnew guidelines\n</laravel-boost-guidelines>"); |
| 334 | + expect($content)->toBe("# Existing content\n\nSome text here.\n\n===\n\n<laravel-boost-guidelines>\nnew guidelines\n</laravel-boost-guidelines>"); |
333 | 335 |
|
334 | 336 | unlink($tempFile); |
335 | 337 | }); |
0 commit comments