From c90c1ed8fa4176e8b40ef7222149fd009d1cee59 Mon Sep 17 00:00:00 2001 From: Gregor Vostrak Date: Wed, 8 Jul 2026 18:24:04 +0200 Subject: [PATCH] add stable secondary sorting based on id to the tests to avoid flakyness --- tests/Unit/Endpoint/Api/V1/ClientEndpointTest.php | 9 ++++++--- tests/Unit/Endpoint/Api/V1/ReportEndpointTest.php | 2 +- tests/Unit/Endpoint/Api/V1/TagEndpointTest.php | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/Unit/Endpoint/Api/V1/ClientEndpointTest.php b/tests/Unit/Endpoint/Api/V1/ClientEndpointTest.php index f2cf0fce..ee31af98 100644 --- a/tests/Unit/Endpoint/Api/V1/ClientEndpointTest.php +++ b/tests/Unit/Endpoint/Api/V1/ClientEndpointTest.php @@ -45,7 +45,7 @@ class ClientEndpointTest extends ApiEndpointTestAbstract // Assert $response->assertStatus(200); $response->assertJsonCount(4, 'data'); - $clients = Client::query()->orderBy('created_at', 'desc')->get(); + $clients = Client::query()->orderBy('created_at', 'desc')->orderBy('id')->get(); $response->assertJson(fn (AssertableJson $json) => $json ->has('data') ->has('links') @@ -84,9 +84,12 @@ class ClientEndpointTest extends ApiEndpointTestAbstract ->has('links') ->has('meta') ->count('data', 2) - ->where('data.0.id', $clients->get(0)->getKey()) - ->where('data.1.id', $clients->get(1)->getKey()) ); + // Both clients share the same created_at, so their relative order is not defined. + $this->assertEqualsCanonicalizing([ + $clients->get(0)->getKey(), + $clients->get(1)->getKey(), + ], $response->json('data.*.id')); } public function test_index_endpoint_without_filter_archived_returns_only_non_archived_clients(): void diff --git a/tests/Unit/Endpoint/Api/V1/ReportEndpointTest.php b/tests/Unit/Endpoint/Api/V1/ReportEndpointTest.php index 9b298f98..5c7df59f 100644 --- a/tests/Unit/Endpoint/Api/V1/ReportEndpointTest.php +++ b/tests/Unit/Endpoint/Api/V1/ReportEndpointTest.php @@ -52,7 +52,7 @@ class ReportEndpointTest extends ApiEndpointTestAbstract // Assert $response->assertStatus(200); $response->assertJsonCount(4, 'data'); - $reports = Report::query()->orderBy('created_at', 'desc')->get(); + $reports = Report::query()->orderBy('created_at', 'desc')->orderBy('id')->get(); $response->assertJson(fn (AssertableJson $json) => $json ->has('data') ->has('links') diff --git a/tests/Unit/Endpoint/Api/V1/TagEndpointTest.php b/tests/Unit/Endpoint/Api/V1/TagEndpointTest.php index d3b35f2a..675cb37a 100644 --- a/tests/Unit/Endpoint/Api/V1/TagEndpointTest.php +++ b/tests/Unit/Endpoint/Api/V1/TagEndpointTest.php @@ -44,7 +44,7 @@ class TagEndpointTest extends ApiEndpointTestAbstract // Assert $response->assertStatus(200); $response->assertJsonCount(4, 'data'); - $tags = Tag::query()->orderBy('created_at', 'desc')->get(); + $tags = Tag::query()->orderBy('created_at', 'desc')->orderBy('id')->get(); $response->assertJson(fn (AssertableJson $json) => $json ->has('data') ->has('links')