diff --git a/framework/core/tests/integration/api/users/GroupSearchTest.php b/framework/core/tests/integration/api/users/GroupSearchTest.php index f0079872d..81401e4dc 100644 --- a/framework/core/tests/integration/api/users/GroupSearchTest.php +++ b/framework/core/tests/integration/api/users/GroupSearchTest.php @@ -147,10 +147,8 @@ class GroupSearchTest extends TestCase $responseBodyContents = json_decode($response->getBody()->getContents(), true); $this->assertCount(4, $responseBodyContents['data'], json_encode($responseBodyContents)); $this->assertCount(4, $responseBodyContents['included'], json_encode($responseBodyContents)); - $this->assertEquals(1, $responseBodyContents['included'][0]['id']); - $this->assertEquals(4, $responseBodyContents['included'][1]['id']); - $this->assertEquals(5, $responseBodyContents['included'][2]['id']); - $this->assertEquals(6, $responseBodyContents['included'][3]['id']); + + $this->assertEqualsCanonicalizing([1, 4, 5, 6], array_column($responseBodyContents['included'], 'id')); } /** @@ -223,11 +221,8 @@ class GroupSearchTest extends TestCase $responseBodyContents = json_decode($response->getBody()->getContents(), true); $this->assertCount(5, $responseBodyContents['data'], json_encode($responseBodyContents)); $this->assertCount(5, $responseBodyContents['included'], json_encode($responseBodyContents)); - $this->assertEquals(1, $responseBodyContents['included'][0]['id']); - $this->assertEquals(99, $responseBodyContents['included'][1]['id']); - $this->assertEquals(4, $responseBodyContents['included'][2]['id']); - $this->assertEquals(5, $responseBodyContents['included'][3]['id']); - $this->assertEquals(6, $responseBodyContents['included'][4]['id']); + + $this->assertEqualsCanonicalizing([1, 99, 4, 5, 6], array_column($responseBodyContents['included'], 'id')); } private function createRequest(array $group, int $userId = null) diff --git a/framework/core/tests/integration/extenders/ApiControllerTest.php b/framework/core/tests/integration/extenders/ApiControllerTest.php index 0ce53463b..910bdb542 100644 --- a/framework/core/tests/integration/extenders/ApiControllerTest.php +++ b/framework/core/tests/integration/extenders/ApiControllerTest.php @@ -146,7 +146,6 @@ class ApiControllerTest extends TestCase ->endpoint(Show::class, function (Show $endpoint): Show { return $endpoint->after(function (Context $context, object $model) { $model->title = 'dataSerializationPrepCustomTitle4'; - return $model; }); }), @@ -649,7 +648,7 @@ class ApiControllerTest extends TestCase (new Extend\ApiResource(UserResource::class)) ->endpoint(Index::class, function (Index $endpoint) use (&$users) { return $endpoint - ->eagerLoad(['firstLevelRelation', 'firstLevelRelation.secondLevelRelation']) + ->eagerLoad(['firstLevelRelation.secondLevelRelation']) ->after(function ($context, $data) use (&$users) { $users = $data; @@ -680,7 +679,7 @@ class ApiControllerTest extends TestCase (new Extend\ApiResource(UserResource::class)) ->endpoint(Index::class, function (Index $endpoint) use (&$users) { return $endpoint - ->eagerLoad(['firstLevelRelation.secondLevelRelation']) + ->eagerLoadWhenIncluded(['firstLevelRelation' => ['secondLevelRelation']]) ->after(function ($context, $data) use (&$users) { $users = $data; @@ -762,73 +761,6 @@ class ApiControllerTest extends TestCase $this->assertFalse($users->pluck('firstLevelRelation')->filter->relationLoaded('secondLevelRelation')->isEmpty()); } - - /** - * @test - */ - public function custom_callable_second_level_relation_is_not_loaded_when_first_level_is_not() - { - $users = null; - - $this->extend( - (new Extend\Model(User::class)) - ->hasOne('firstLevelRelation', Post::class, 'user_id'), - (new Extend\Model(Post::class)) - ->belongsTo('secondLevelRelation', Discussion::class), - (new Extend\ApiResource(UserResource::class)) - ->endpoint(Index::class, function (Index $endpoint) use (&$users) { - return $endpoint - ->eagerLoadWhere('firstLevelRelation.secondLevelRelation', function ($query, $request) {}) - ->after(function ($context, $data) use (&$users) { - $users = $data; - - return $data; - }); - }) - ); - - $this->send( - $this->request('GET', '/api/users', [ - 'authenticatedAs' => 1, - ]) - ); - - $this->assertTrue($users->pluck('firstLevelRelation')->filter->relationLoaded('secondLevelRelation')->isEmpty()); - } - - /** - * @test - */ - public function custom_callable_second_level_relation_is_loaded_when_first_level_is() - { - $users = null; - - $this->extend( - (new Extend\Model(User::class)) - ->hasOne('firstLevelRelation', Post::class, 'user_id'), - (new Extend\Model(Post::class)) - ->belongsTo('secondLevelRelation', Discussion::class), - (new Extend\ApiResource(UserResource::class)) - ->endpoint(Index::class, function (Index $endpoint) use (&$users) { - return $endpoint - ->eagerLoadWhere('firstLevelRelation', function ($query, $request) {}) - ->eagerLoadWhere('firstLevelRelation.secondLevelRelation', function ($query, $request) {}) - ->after(function ($context, $data) use (&$users) { - $users = $data; - - return $data; - }); - }) - ); - - $this->send( - $this->request('GET', '/api/users', [ - 'authenticatedAs' => 1, - ]) - ); - - $this->assertTrue($users->pluck('firstLevelRelation')->filter->relationLoaded('secondLevelRelation')->isNotEmpty()); - } } class CustomAfterEndpointInvokableClass