Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6522e47

Browse files
committed
Test to avoid adding extra newline
1 parent 93e9d8e commit 6522e47

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

‎tests/Unit/Install/GuidelineWriterTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,29 @@
100100
unlink($tempFile);
101101
});
102102

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+
103126
test('it handles multiline existing guidelines', function () {
104127
$tempFile = tempnam(sys_get_temp_dir(), 'boost_test_');
105128
$initialContent = "Start\n<laravel-boost-guidelines>\nline 1\nline 2\nline 3\n</laravel-boost-guidelines>\nEnd";

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /