Skip to content

Commit a3a7afe

Browse files
committed
test: fix tests now indentation changed to count of spaces rather than a string
1 parent 7ef74d3 commit a3a7afe

File tree

3 files changed

+12
-24
lines changed

3 files changed

+12
-24
lines changed

src/Install/Mcp/FileWriter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ protected function injectNewConfigKey(string $content): bool
152152
return $this->writeFile($newContent);
153153
}
154154

155-
protected function generateServerJson(string $key, array $serverConfig, int $baseIndent = 8): string
155+
protected function generateServerJson(string $key, array $serverConfig, int $baseIndent = 0): string
156156
{
157157
$json = json_encode($serverConfig, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
158158

tests/Unit/Install/Detection/FileDetectionStrategyTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
use Laravel\Boost\Install\Detection\FileDetectionStrategy;
66

77
beforeEach(function () {
8-
$this->strategy = new FileDetectionStrategy();
8+
$this->strategy = new FileDetectionStrategy;
99
$this->tempDir = sys_get_temp_dir().'/boost_test_'.uniqid();
1010
mkdir($this->tempDir);
1111
});
1212

1313
afterEach(function () {
14-
if (is_dir($this->tempDir)) {
14+
if (is_dir($this->tempDir) && str_contains($this->tempDir, sys_get_temp_dir())) {
1515
removeDirectoryForFileTests($this->tempDir);
1616
}
1717
});

tests/Unit/Install/Mcp/FileWriterTest.php

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@
325325
expect($writtenContent)->toContain('arg1'); // Existing args preserved
326326
});
327327

328-
test('detectIndentation works correctly with various patterns', function (string $content, int $position, string $expected, string $description) {
328+
test('detectIndentation works correctly with various patterns', function (string $content, int $position, int $expected, string $description) {
329329
$writer = new FileWriter('/tmp/test.json');
330330

331331
$result = $writer->detectIndentation($content, $position);
@@ -513,61 +513,49 @@ function indentationDetectionCases(): array
513513
'mcp.json5 servers indentation' => [
514514
'content' => "{\n // Here are comments within my JSON\n \"servers\": {\n \"mysql\": {\n \"command\": \"npx\"\n },\n \"laravel-boost\": {\n \"command\": \"php\"\n }\n },\n \"inputs\": []\n}",
515515
'position' => 200, // Position near end of servers block
516-
'expected' => ' ', // 8 spaces for server-level items
516+
'expected' => 8,
517517
'description' => 'Should detect 8 spaces for server definitions in mcp.json5',
518518
],
519519
'nested object with 4-space base indent' => [
520520
'content' => "{\n \"config\": {\n \"server1\": {\n \"command\": \"test\"\n }\n }\n}",
521521
'position' => 80,
522-
'expected' => ' ', // 8 spaces for server-level
522+
'expected' => 8,
523523
'description' => 'Should detect 8 spaces for nested server definitions',
524524
],
525525
'no previous server definitions' => [
526526
'content' => "{\n \"inputs\": []\n}",
527527
'position' => 20,
528-
'expected' => ' ', // Fallback to 8 spaces
528+
'expected' => 8,
529529
'description' => 'Should fallback to 8 spaces when no server definitions found',
530530
],
531-
'tab-indented servers' => [
532-
'content' => "{\n\t\"servers\": {\n\t\t\"mysql\": {\n\t\t\t\"command\": \"npx\"\n\t\t}\n\t}\n}",
533-
'position' => 50,
534-
'expected' => "\t\t", // 2 tabs for server-level
535-
'description' => 'Should detect tab indentation for server definitions',
536-
],
537-
'mixed indentation with tabs and spaces' => [
538-
'content' => "{\n \t\"servers\": {\n \t \"mysql\": {\n \t \"command\": \"npx\"\n \t }\n \t}\n}",
539-
'position' => 70,
540-
'expected' => " \t ", // Mixed indentation preserved
541-
'description' => 'Should preserve mixed tab/space indentation',
542-
],
543531
'deeper nesting with 2-space indent' => [
544532
'content' => "{\n \"config\": {\n \"servers\": {\n \"mysql\": {\n \"command\": \"test\"\n }\n }\n }\n}",
545533
'position' => 80,
546-
'expected' => ' ', // 6 spaces for server-level in deeper nesting
534+
'expected' => 6,
547535
'description' => 'Should detect correct indentation in deeply nested structures',
548536
],
549537
'single server definition at root level' => [
550538
'content' => "{\n\"mysql\": {\n \"command\": \"npx\"\n}\n}",
551539
'position' => 30,
552-
'expected' => '', // No indentation at root level
540+
'expected' => 0,
553541
'description' => 'Should detect no indentation for root-level server definitions',
554542
],
555543
'multiple server definitions with consistent indentation' => [
556544
'content' => "{\n \"servers\": {\n \"mysql\": {\n \"command\": \"npx\"\n },\n \"postgres\": {\n \"command\": \"pg\"\n }\n }\n}",
557545
'position' => 150,
558-
'expected' => ' ', // 8 spaces
546+
'expected' => 8,
559547
'description' => 'Should consistently detect indentation across multiple servers',
560548
],
561549
'server definition with comments' => [
562550
'content' => "{\n // Comment here\n \"servers\": {\n \"mysql\": { // inline comment\n \"command\": \"npx\"\n }\n }\n}",
563551
'position' => 120,
564-
'expected' => ' ', // 8 spaces
552+
'expected' => 8,
565553
'description' => 'Should detect indentation correctly when comments are present',
566554
],
567555
'empty content' => [
568556
'content' => '',
569557
'position' => 0,
570-
'expected' => ' ', // Fallback
558+
'expected' => 8,
571559
'description' => 'Should fallback to 8 spaces for empty content',
572560
],
573561
];

0 commit comments

Comments
 (0)