Skip to content

Commit b87236e

Browse files
authored
[1.x] Improve tests (#386)
* Refactor multiselect test assertions for improved readability * Refactor browser logger script assertions for improved readability * Refactor test assertions for improved readability * Refactor assertions in BrowserLogsTest for improved readability * Refactor assertions in ListArtisanCommandsTest for improved readability * Refactor assertions in ListAvailableConfigKeysTest for improved readability * Refactor assertions in ListRoutesTest for improved readability * Refactor assertions in DisplayHelperTest for improved readability * Refactor assertions in FileWriterTest for improved readability * Refactor assertions in GuidelineWriterTest for improved readability * Refactor assertions in InstallCommandMultiselectTest for improved readability * Refactor assertions in ListAvailableConfigKeysTest for improved readability
1 parent b26b1aa commit b87236e

File tree

9 files changed

+109
-123
lines changed

9 files changed

+109
-123
lines changed

tests/Feature/Console/InstallCommandMultiselectTest.php

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,10 @@
2525
);
2626

2727
// Assert that we get the keys, not the values
28-
expect($result)->toBeArray();
29-
expect($result)->toHaveCount(2, 'Should have 2 items selected');
30-
expect($result)->toContain('mcp_server');
31-
expect($result)->toContain('ai_guidelines');
32-
expect($result)->not->toContain('Boost MCP Server');
33-
expect($result)->not->toContain('Package AI Guidelines');
28+
expect($result)->toBeArray()
29+
->toHaveCount(2, 'Should have 2 items selected')
30+
->toContain('mcp_server', 'ai_guidelines')
31+
->not->toContain('Boost MCP Server', 'Package AI Guidelines');
3432
})->skipOnWindows();
3533

3634
test('multiselect returns values for indexed array', function (): void {
@@ -48,9 +46,8 @@
4846
);
4947

5048
// For indexed arrays, it returns the actual values
51-
expect($result)->toBeArray();
52-
expect($result)->toContain('Option 1');
53-
expect($result)->toContain('Option 2');
49+
expect($result)->toBeArray()
50+
->toContain('Option 1', 'Option 2');
5451
})->skipOnWindows();
5552

5653
test('multiselect behavior matches install command expectations', function (): void {
@@ -79,10 +76,7 @@
7976

8077
// Verify we get keys that can be used with in_array checks
8178
expect($result)->toBeArray()
82-
->and($result)->toHaveCount(3)
83-
->and($result)->toContain('mcp_server')
84-
->and($result)->toContain('ai_guidelines')
85-
->and($result)->toContain('style_guidelines')
86-
->and($result)->not->toContain('Boost MCP Server')
87-
->and($result)->not->toContain('Package AI Guidelines (i.e. Framework, Inertia, Pest)');
79+
->toHaveCount(3)
80+
->toContain('mcp_server', 'ai_guidelines', 'style_guidelines')
81+
->not->toContain('Boost MCP Server', 'Package AI Guidelines (i.e. Framework, Inertia, Pest)');
8882
})->skipOnWindows();

tests/Feature/Install/CodeEnvironment/CodeEnvironmentPathResolutionTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
// Should be an absolute path ending with 'artisan'
2323
expect($artisanPath)->toEndWith('artisan')
24-
->and($artisanPath)->not()->toBe('artisan');
24+
->not->toBe('artisan');
2525
});
2626

2727
test('Cursor returns relative php string', function (): void {
@@ -44,7 +44,7 @@
4444

4545
expect($cursor->getPhpPath(true))->toBe(PHP_BINARY);
4646
expect($cursor->getArtisanPath(true))->toEndWith('artisan')
47-
->and($cursor->getArtisanPath(true))->not()->toBe('artisan');
47+
->not->toBe('artisan');
4848
});
4949

5050
test('CodeEnvironment maintains relative paths when forceAbsolutePath is false', function (): void {
@@ -65,7 +65,7 @@
6565

6666
$artisanPath = $phpStorm->getArtisanPath(true);
6767
expect($artisanPath)->toEndWith('artisan')
68-
->and($artisanPath)->not()->toBe('artisan');
68+
->not->toBe('artisan');
6969

7070
expect($phpStorm->getArtisanPath(false))->toBe($artisanPath);
7171
});

tests/Feature/Mcp/Tools/BrowserLogsTest.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,14 @@
9494

9595
// Test that the script contains expected content
9696
$script = BrowserLogger::getScript();
97-
expect($script)->toContain('browser-logger-active')
98-
->and($script)->toContain('/_boost/browser-logs')
99-
->and($script)->toContain('console.log')
100-
->and($script)->toContain('console.error')
101-
->and($script)->toContain('window.onerror');
97+
98+
expect($script)->toContain(
99+
'browser-logger-active',
100+
'/_boost/browser-logs',
101+
'console.log',
102+
'console.error',
103+
'window.onerror'
104+
);
102105
});
103106

104107
test('browser logs endpoint processes logs correctly', function (): void {
@@ -202,7 +205,7 @@
202205

203206
$content = $result->getContent();
204207
expect($content)->toContain('browser-logger-active')
205-
->and($content)->toContain('</head>')
208+
->toContain('</head>')
206209
// Should not inject twice
207210
->and(substr_count($content, 'browser-logger-active'))->toBe(1);
208211
});
@@ -219,7 +222,7 @@
219222

220223
$content = $result->getContent();
221224
expect($content)->toBe($json)
222-
->and($content)->not->toContain('browser-logger-active');
225+
->not->toContain('browser-logger-active');
223226
});
224227

225228
test('InjectBoost middleware does not inject script twice', function (): void {
@@ -266,5 +269,5 @@
266269

267270
$content = $result->getContent();
268271
expect($content)->toContain('browser-logger-active')
269-
->and($content)->toMatch('/<script[^>]*browser-logger-active[^>]*>.*<\/script>\s*<\/body>/s');
272+
->toMatch('/<script[^>]*browser-logger-active[^>]*>.*<\/script>\s*<\/body>/s');
270273
});

tests/Feature/Mcp/Tools/ListArtisanCommandsTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
->toolHasNoError()
1414
->toolJsonContent(function ($content): void {
1515
expect($content)->toBeArray()
16-
->and($content)->not->toBeEmpty();
16+
->not->toBeEmpty();
1717

1818
// Check that it contains some basic Laravel commands
1919
$commandNames = array_column($content, 'name');
2020
expect($commandNames)->toContain('migrate')
21-
->and($commandNames)->toContain('make:model')
22-
->and($commandNames)->toContain('route:list');
21+
->toContain('make:model')
22+
->toContain('route:list');
2323

2424
// Check the structure of each command
2525
foreach ($content as $command) {

tests/Feature/Mcp/Tools/ListAvailableConfigKeysTest.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,18 @@
1919
->toolHasNoError()
2020
->toolJsonContent(function ($content): void {
2121
expect($content)->toBeArray()
22-
->and($content)->not->toBeEmpty()
23-
// Check that it contains common Laravel config keys
24-
->and($content)->toContain('app.name')
25-
->and($content)->toContain('app.env')
26-
->and($content)->toContain('database.default')
27-
// Check that it contains our test keys
28-
->and($content)->toContain('test.simple')
29-
->and($content)->toContain('test.nested.key')
30-
->and($content)->toContain('test.array.0')
31-
->and($content)->toContain('test.array.1');
22+
->not->toBeEmpty()
23+
->toContain(
24+
// Check that it constains common Laravel config keys
25+
'app.name',
26+
'app.env',
27+
'database.default',
28+
// Check that it contains our test keys
29+
'test.simple',
30+
'test.nested.key',
31+
'test.array.0',
32+
'test.array.1'
33+
);
3234

3335
// Check that keys are sorted
3436
$sortedContent = $content;
@@ -49,6 +51,6 @@
4951
->toolJsonContent(function ($content): void {
5052
expect($content)->toBeArray()
5153
// Should still have Laravel default config keys
52-
->and($content)->toContain('app.name');
54+
->toContain('app.name');
5355
});
5456
});

tests/Feature/Mcp/Tools/ListRoutesTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@
3737
expect($response)->isToolResult()
3838
->toolHasNoError()
3939
->toolTextContains('admin.dashboard', 'admin.users.store')
40-
->and($response)->not->toolTextContains('user.profile', 'two-factor.enable');
40+
->not->toolTextContains('user.profile', 'two-factor.enable');
4141

4242
$response = $tool->handle(new Request(['name' => '*two-factor*']));
4343

4444
expect($response)->toolTextContains('two-factor.enable')
45-
->and($response)->not->toolTextContains('admin.dashboard', 'user.profile');
45+
->not->toolTextContains('admin.dashboard', 'user.profile');
4646

4747
$response = $tool->handle(new Request(['name' => '*api*']));
4848

4949
expect($response)->toolTextContains('api.posts.index', 'api.posts.update')
50-
->and($response)->not->toolTextContains('admin.dashboard', 'user.profile');
50+
->not->toolTextContains('admin.dashboard', 'user.profile');
5151

5252
});
5353

@@ -63,12 +63,12 @@
6363
$response = $tool->handle(new Request(['method' => '*GET*']));
6464

6565
expect($response)->toolTextContains('admin.dashboard', 'user.profile', 'api.posts.index')
66-
->and($response)->not->toolTextContains('admin.users.store');
66+
->not->toolTextContains('admin.users.store');
6767

6868
$response = $tool->handle(new Request(['method' => '*POST*']));
6969

7070
expect($response)->toolTextContains('admin.users.store')
71-
->and($response)->not->toolTextContains('admin.dashboard');
71+
->not->toolTextContains('admin.dashboard');
7272
});
7373

7474
test('it handles edge cases and empty results correctly', function (): void {

tests/Unit/Install/Cli/DisplayHelperTest.php

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,7 @@
2121
]);
2222
$output = ob_get_clean();
2323

24-
expect($output)->toContain('Name')
25-
->and($output)->toContain('Age')
26-
->and($output)->toContain('')
27-
->and($output)->toContain('')
28-
->and($output)->toContain('')
29-
->and($output)->toContain('');
24+
expect($output)->toContain('Name', 'Age', '', '', '', '');
3025
});
3126

3227
it('displays a multi-row table', function (): void {
@@ -38,12 +33,7 @@
3833
]);
3934
$output = ob_get_clean();
4035

41-
expect($output)->toContain('Name')
42-
->and($output)->toContain('John')
43-
->and($output)->toContain('Jane')
44-
->and($output)->toContain('')
45-
->and($output)->toContain('')
46-
->and($output)->toContain('');
36+
expect($output)->toContain('Name', 'John', 'Jane', '', '', '');
4737
});
4838

4939
it('handles different data types in cells', function (): void {
@@ -55,11 +45,7 @@
5545
]);
5646
$output = ob_get_clean();
5747

58-
expect($output)->toContain('text')
59-
->and($output)->toContain('123')
60-
->and($output)->toContain('true')
61-
->and($output)->toContain('another')
62-
->and($output)->toContain('456');
48+
expect($output)->toContain('text', '123', 'true', 'another', '456');
6349
});
6450

6551
it('applies bold formatting to first column', function (): void {
@@ -70,8 +56,7 @@
7056
]);
7157
$output = ob_get_clean();
7258

73-
expect($output)->toContain("\e[1mHeader1\e[0m")
74-
->and($output)->toContain("\e[1mValue1\e[0m")
59+
expect($output)->toContain("\e[1mHeader1\e[0m", "\e[1mValue1\e[0m")
7560
->and($output)->not->toContain("\e[1mHeader2\e[0m");
7661
});
7762

@@ -83,10 +68,7 @@
8368
]);
8469
$output = ob_get_clean();
8570

86-
expect($output)->toContain('名前')
87-
->and($output)->toContain('Émile')
88-
->and($output)->toContain('測試')
89-
->and($output)->toContain('café');
71+
expect($output)->toContain('名前', 'Émile', '測試', 'café');
9072
});
9173
});
9274

@@ -104,51 +86,39 @@
10486
DisplayHelper::grid(['Item1']);
10587
$output = ob_get_clean();
10688

107-
expect($output)->toContain('Item1')
108-
->and($output)->toContain('')
109-
->and($output)->toContain('')
110-
->and($output)->toContain('')
111-
->and($output)->toContain('');
89+
expect($output)->toContain('Item1', '', '', '', '');
11290
});
11391

11492
it('displays multiple items in grid', function (): void {
11593
ob_start();
11694
DisplayHelper::grid(['Item1', 'Item2', 'Item3', 'Item4']);
11795
$output = ob_get_clean();
11896

119-
expect($output)->toContain('Item1')
120-
->and($output)->toContain('Item2')
121-
->and($output)->toContain('Item3')
122-
->and($output)->toContain('Item4');
97+
expect($output)->toContain('Item1', 'Item2', 'Item3', 'Item4');
12398
});
12499

125100
it('handles items of different lengths', function (): void {
126101
ob_start();
127102
DisplayHelper::grid(['Short', 'Very Long Item Name', 'Med']);
128103
$output = ob_get_clean();
129104

130-
expect($output)->toContain('Short')
131-
->and($output)->toContain('Very Long Item Name')
132-
->and($output)->toContain('Med');
105+
expect($output)->toContain('Short', 'Very Long Item Name', 'Med');
133106
});
134107

135108
it('respects column width parameter', function (): void {
136109
ob_start();
137110
DisplayHelper::grid(['Item1', 'Item2'], 40);
138111
$output = ob_get_clean();
139112

140-
expect($output)->toContain('Item1')
141-
->and($output)->toContain('Item2');
113+
expect($output)->toContain('Item1', 'Item2');
142114
});
143115

144116
it('handles unicode characters in grid', function (): void {
145117
ob_start();
146118
DisplayHelper::grid(['測試', 'café', '🚀']);
147119
$output = ob_get_clean();
148120

149-
expect($output)->toContain('測試')
150-
->and($output)->toContain('café')
151-
->and($output)->toContain('🚀');
121+
expect($output)->toContain('測試', 'café', '🚀');
152122
});
153123

154124
it('fills empty cells when items do not fill complete rows', function (): void {

tests/Unit/Install/GuidelineWriterTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,12 @@
265265
->and($content)->toContain('updated guidelines from boost');
266266

267267
// Verify user content after guidelines is preserved
268-
expect($content)->toContain('# User Added Section')
269-
->and($content)->toContain('This content was added by the user after the guidelines.')
270-
->and($content)->toContain('## Another user section')
271-
->and($content)->toContain('More content here.');
268+
expect($content)->toContain(
269+
'# User Added Section',
270+
'This content was added by the user after the guidelines.',
271+
'## Another user section',
272+
'More content here.'
273+
);
272274

273275
// Verify exact structure
274276
expect($content)->toBe("# My Project\n\n<laravel-boost-guidelines>\nupdated guidelines from boost\n</laravel-boost-guidelines>\n\n# User Added Section\nThis content was added by the user after the guidelines.\n\n## Another user section\nMore content here.\n");

0 commit comments

Comments
 (0)