|
100 | 100 | unlink($tempFile);
|
101 | 101 | });
|
102 | 102 |
|
| 103 | +test('it avoids adding extra newline if one already exists', function () { |
| 104 | + $tempFile = tempnam(sys_get_temp_dir(), 'boost_test_'); |
| 105 | + $initialContent = "# Header\n\n<laravel-boost-guidelines>\nold guidelines\n</laravel-boost-guidelines>\n\n# Footer\n"; |
| 106 | + file_put_contents($tempFile, $initialContent); |
| 107 | + |
| 108 | + $agent = Mockery::mock(Agent::class); |
| 109 | + $agent->shouldReceive('guidelinesPath')->andReturn($tempFile); |
| 110 | + $agent->shouldReceive('frontmatter')->andReturn(false); |
| 111 | + |
| 112 | + $writer = new GuidelineWriter($agent); |
| 113 | + $writer->write('updated guidelines'); |
| 114 | + |
| 115 | + $content = file_get_contents($tempFile); |
| 116 | + expect($content)->toBe("# Header\n\n<laravel-boost-guidelines>\nupdated guidelines\n</laravel-boost-guidelines>\n\n# Footer\n"); |
| 117 | + |
| 118 | + // Assert no double newline at the end |
| 119 | + expect(substr($content, -2))->not->toBe("\n\n"); |
| 120 | + // Assert still ends with exactly one newline |
| 121 | + expect(substr($content, -1))->toBe("\n"); |
| 122 | + |
| 123 | + unlink($tempFile); |
| 124 | +}); |
| 125 | + |
103 | 126 | test('it handles multiline existing guidelines', function () {
|
104 | 127 | $tempFile = tempnam(sys_get_temp_dir(), 'boost_test_');
|
105 | 128 | $initialContent = "Start\n<laravel-boost-guidelines>\nline 1\nline 2\nline 3\n</laravel-boost-guidelines>\nEnd";
|
|
0 commit comments