From fa601958e2ddbec404e516f3b9617bb66dc7f4d3 Mon Sep 17 00:00:00 2001 From: Arie Timmerman Date: Mon, 30 Sep 2024 22:08:04 +0200 Subject: [PATCH] Ensure resource types are presented correctly in list response (#93) --- src/Helper.php | 2 +- src/SCIM/ResourceType.php | 3 ++- tests/ResourceTypesTest.php | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/Helper.php b/src/Helper.php index d97ac7cd..73f65678 100644 --- a/src/Helper.php +++ b/src/Helper.php @@ -50,7 +50,7 @@ public static function prepareReturn(Arrayable $object, ResourceType $resourceTy public static function objectToSCIMArray($object, ResourceType $resourceType = null, array $attributes = []) { if($resourceType == null){ - return $object; + return $object instanceof Arrayable ? $object->toArray() : $object; } $mapping = $resourceType->getMapping(); diff --git a/src/SCIM/ResourceType.php b/src/SCIM/ResourceType.php index 34892e2f..7d310e3e 100644 --- a/src/SCIM/ResourceType.php +++ b/src/SCIM/ResourceType.php @@ -2,9 +2,10 @@ namespace ArieTimmerman\Laravel\SCIMServer\SCIM; +use Illuminate\Contracts\Support\Arrayable; use Illuminate\Contracts\Support\Jsonable; -class ResourceType implements Jsonable +class ResourceType implements Jsonable, Arrayable { public $id; diff --git a/tests/ResourceTypesTest.php b/tests/ResourceTypesTest.php index f5ff9303..10fd8a29 100644 --- a/tests/ResourceTypesTest.php +++ b/tests/ResourceTypesTest.php @@ -16,6 +16,26 @@ public function testGet() { $response = $this->get('/scim/v2/ResourceTypes'); $response->assertStatus(200); + + $response->assertJsonStructure([ + 'schemas', + 'totalResults', + 'Resources' => [ + '*' => [ + 'schemas', + 'id', + 'name', + 'endpoint', + 'description', + 'schema', + 'schemaExtensions', + 'meta' => [ + 'location', + 'resourceType' + ] + ] + ] + ]); } public function testGetOne(){