Skip to content

Commit fcc5187

Browse files
chore: Fix tests when run sequentially (#702)
* chore: Test with PHP 8.5 * Exclude L11 from PHP 8.5 * Update github actions * fix * chore: Fix tests when run sequentially
1 parent f68aee8 commit fcc5187

File tree

3 files changed

+35
-13
lines changed

3 files changed

+35
-13
lines changed

tests/MCP/McpActionsIntegrationTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ protected function getPackageProviders($app): array
3232
]);
3333
}
3434

35+
protected function tearDown(): void
36+
{
37+
// Clear Restify repositories to prevent affecting subsequent tests
38+
Restify::$repositories = [];
39+
40+
parent::tearDown();
41+
}
42+
3543
public function test_could_perform_action_for_multiple_repositories(): void
3644
{
3745
PublishPostAction::$applied = [];

tests/MCP/McpFieldsIntegrationTest.php

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ protected function getPackageProviders($app): array
3333
]);
3434
}
3535

36-
protected function setUp(): void
36+
protected function tearDown(): void
3737
{
38-
parent::setUp();
38+
// Clear Restify repositories to prevent affecting subsequent tests
39+
Restify::$repositories = [];
3940

40-
// Clear any previously registered repositories to avoid test pollution
41-
Restify::repositories([]);
41+
parent::tearDown();
4242
}
4343

4444
public function test_repository_uses_mcp_specific_field_methods(): void
@@ -253,11 +253,15 @@ public function mcpAllowsIndex(): bool
253253

254254
// Find our expected tool name
255255
$availableTools = collect($toolsData['result']['tools'])->pluck('name')->toArray();
256-
$indexToolName = collect($availableTools)->filter(fn ($name) => str_contains($name,
257-
'test-posts') && str_contains($name, 'index'))->first();
256+
$indexToolName = collect($availableTools)->filter(fn ($name) => str_contains(
257+
$name,
258+
'test-posts'
259+
) && str_contains($name, 'index'))->first();
258260

259-
$this->assertNotNull($indexToolName,
260-
'Expected test-posts index tool not found. Available tools: '.implode(', ', $availableTools));
261+
$this->assertNotNull(
262+
$indexToolName,
263+
'Expected test-posts index tool not found. Available tools: '.implode(', ', $availableTools)
264+
);
261265

262266
// Create MCP JSON-RPC 2.0 request payload for calling the index tool
263267
$mcpPayload = [
@@ -305,8 +309,11 @@ public function mcpAllowsIndex(): bool
305309
// Check structure - JSON:API format has 'attributes' key
306310
if (isset($firstItem['type']) && isset($firstItem['id'])) {
307311
// JSON:API format - attributes should be in a sub-key
308-
$this->assertArrayHasKey('attributes', $firstItem,
309-
'Expected JSON:API structure with attributes key. Found keys: '.implode(', ', array_keys($firstItem)));
312+
$this->assertArrayHasKey(
313+
'attributes',
314+
$firstItem,
315+
'Expected JSON:API structure with attributes key. Found keys: '.implode(', ', array_keys($firstItem))
316+
);
310317
$attributes = $firstItem['attributes'];
311318
} elseif (isset($firstItem['attributes'])) {
312319
// Has attributes key but not standard JSON:API
@@ -418,8 +425,10 @@ public function mcpAllowsIndex(): bool
418425
fn ($name) => str_contains($name, 'test-posts-with-user') && str_contains($name, 'index')
419426
)->first();
420427

421-
$this->assertNotNull($postIndexToolName,
422-
'Expected test-posts-with-user index tool not found. Available tools: '.implode(', ', $availableTools));
428+
$this->assertNotNull(
429+
$postIndexToolName,
430+
'Expected test-posts-with-user index tool not found. Available tools: '.implode(', ', $availableTools)
431+
);
423432

424433
// Create MCP request with relationship inclusion
425434
$mcpPayload = [

tests/MCP/WrapperToolsIntegrationTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,14 @@ protected function setUp(): void
3737
})
3838
->shouldReceive('flush')
3939
->andReturn(true);
40+
}
4041

41-
// Reset Restify repositories to prevent cross-test contamination
42+
protected function tearDown(): void
43+
{
44+
// Clear Restify repositories to prevent affecting subsequent tests
4245
Restify::$repositories = [];
46+
47+
parent::tearDown();
4348
}
4449

4550
protected function getPackageProviders($app): array

0 commit comments

Comments
 (0)