Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
timacdonald committed Oct 11, 2023
1 parent da975ac commit 07f9afc
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 34 deletions.
4 changes: 2 additions & 2 deletions src/JsonApiResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ public function toArray($request)
public function with($request)
{
return [
...$included = $this->included($request)
...($included = $this->included($request)
->uniqueStrict(fn (JsonApiResource $resource): string => $resource->toUniqueResourceIdentifier($request))
->values()
->all() ? ['included' => $included] : [],
->all()) ? ['included' => $included] : [],
'jsonapi' => self::serverImplementationResolver()($request),
];
}
Expand Down
5 changes: 3 additions & 2 deletions src/JsonApiResourceCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ private function resolveResourceIdentifiers(Request $request)
public function with($request)
{
return [
'included' => $this->collection
...($included = $this->collection
->map(fn (JsonApiResource $resource): Collection => $resource->included($request))
->flatten()
->uniqueStrict(fn (JsonApiResource $resource): string => $resource->toUniqueResourceIdentifier($request))
->values(),
->values()
->all()) ? ['included' => $included] : [],
'jsonapi' => JsonApiResource::serverImplementationResolver()($request),
];
}
Expand Down
10 changes: 0 additions & 10 deletions tests/Feature/AttributesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public function toAttributes($request): array
'jsonapi' => [
'version' => '1.0',
],
'included' => [],
]);
$this->assertValidJsonApi($response);
}
Expand Down Expand Up @@ -84,7 +83,6 @@ public function toAttributes($request): array
'jsonapi' => [
'version' => '1.0',
],
'included' => [],
]);
$this->assertValidJsonApi($response);
}
Expand Down Expand Up @@ -119,7 +117,6 @@ public function toAttributes($request): array
'jsonapi' => [
'version' => '1.0',
],
'included' => [],
]);
$this->assertValidJsonApi($response);
}
Expand Down Expand Up @@ -153,7 +150,6 @@ public function toAttributes($request): array
'jsonapi' => [
'version' => '1.0',
],
'included' => [],
]);
$this->assertValidJsonApi($response);
}
Expand Down Expand Up @@ -183,7 +179,6 @@ public function toAttributes($request): array
'jsonapi' => [
'version' => '1.0',
],
'included' => [],
]);
$this->assertValidJsonApi($response);
}
Expand Down Expand Up @@ -234,7 +229,6 @@ public function testItCanSpecifyMinimalAttributes(): void
'jsonapi' => [
'version' => '1.0',
],
'included' => [],
]);
$this->assertValidJsonApi($response);
});
Expand Down Expand Up @@ -264,7 +258,6 @@ public function testItCanRequestAttributesWhenUsingMinimalAttributes()
'jsonapi' => [
'version' => '1.0',
],
'included' => [],
]);
$this->assertValidJsonApi($response);
});
Expand Down Expand Up @@ -367,7 +360,6 @@ public function toAttributes($request): array
'jsonapi' => [
'version' => '1.0',
],
'included' => [],
]);
$this->assertValidJsonApi($response);
}
Expand Down Expand Up @@ -407,7 +399,6 @@ public function toAttributes($request): array
'jsonapi' => [
'version' => '1.0',
],
'included' => [],
]);
$this->assertValidJsonApi($response);
}
Expand Down Expand Up @@ -448,7 +439,6 @@ public function toAttributes($request): array
'jsonapi' => [
'version' => '1.0',
],
'included' => [],
]);
$this->assertValidJsonApi($response);
}
Expand Down
1 change: 0 additions & 1 deletion tests/Feature/FeatureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public function testItCanPaginate(): void
],
],
],
'included' => [],
'links' => [
'first' => 'http://localhost/test-route?page=1',
'last' => 'http://localhost/test-route?page=3',
Expand Down
11 changes: 0 additions & 11 deletions tests/Feature/JsonApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public function testItCanReturnASingleResource(): void
'name' => 'user-name',
],
],
'included' => [],
'jsonapi' => [
'version' => '1.0',
],
Expand Down Expand Up @@ -79,7 +78,6 @@ public function testItCanReturnACollection(): void
],
],
],
'included' => [],
'jsonapi' => [
'version' => '1.0',
],
Expand Down Expand Up @@ -122,7 +120,6 @@ public function toMeta($request): array
'meta-key' => 'meta-value',
],
],
'included' => [],
'jsonapi' => [
'version' => '1.0',
],
Expand Down Expand Up @@ -167,7 +164,6 @@ public function toLinks($request): array
],
],
],
'included' => [],
'jsonapi' => [
'version' => '1.0',
],
Expand Down Expand Up @@ -207,7 +203,6 @@ public function testItCanCustomiseTheTypeResolution(): void
'id' => 'expected-id',
'type' => 'Tests\\Models\\BasicModel',
],
'included' => [],
'jsonapi' => [
'version' => '1.0',
],
Expand All @@ -229,7 +224,6 @@ public function testItCanCustomiseTheIdResolution(): void
'id' => 'expected-id',
'type' => 'basicModels',
],
'included' => [],
'jsonapi' => [
'version' => '1.0',
],
Expand Down Expand Up @@ -288,7 +282,6 @@ public function testItCanSpecifyAnImplementation(): void
'name' => 'user-name',
],
],
'included' => [],
'jsonapi' => [
'version' => '1.4.3',
'meta' => [
Expand All @@ -297,8 +290,6 @@ public function testItCanSpecifyAnImplementation(): void
],
]);
$this->assertValidJsonApi($response);

BasicJsonApiResource::resolveServerImplementationNormally();
}

public function testItExcludesEmptyRelationshipLinkMeta()
Expand Down Expand Up @@ -744,7 +735,5 @@ public static function collection($resource): JsonApiResourceCollection
],
]);
$this->assertValidJsonApi($response);

JsonApiResource::resolveServerImplementationNormally();
}
}
6 changes: 0 additions & 6 deletions tests/Feature/RelationshipsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public function toRelationships($request): array
'content' => 'post-content',
],
],
'included' => [],
'jsonapi' => [
'version' => '1.0',
],
Expand Down Expand Up @@ -967,7 +966,6 @@ public function testItHasIncludedArrayWhenIncludeParameterIsPresentForASingleRes
'jsonapi' => [
'version' => '1.0',
],
'included' => [],
]);
$this->assertValidJsonApi($response);
}
Expand Down Expand Up @@ -998,7 +996,6 @@ public function testItHasIncludedArrayWhenIncludeParameterIsPresentForACollectio
'jsonapi' => [
'version' => '1.0',
],
'included' => [],
]);
$this->assertValidJsonApi($response);
}
Expand Down Expand Up @@ -1029,7 +1026,6 @@ public function testItCanReturnNullForEmptyToOneRelationships(): void
'jsonapi' => [
'version' => '1.0',
],
'included' => [],
]);
$this->assertValidJsonApi($response);
}
Expand Down Expand Up @@ -1060,7 +1056,6 @@ public function testItCanReturnAnEmptyArrayForEmptyToManyRelationships(): void
'jsonapi' => [
'version' => '1.0',
],
'included' => [],
]);
$this->assertValidJsonApi($response);
}
Expand Down Expand Up @@ -1292,7 +1287,6 @@ public function toRelationships($request): array
'jsonapi' => [
'version' => '1.0',
],
'included' => [],
]);
$this->assertValidJsonApi($response);
}
Expand Down
2 changes: 0 additions & 2 deletions tests/Feature/ResourceIdentificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ public function testItResolvesTheIdAndTypeOfAModel(): void
'jsonapi' => [
'version' => '1.0',
],
'included' => [],
]);
$this->assertValidJsonApi($response);
}
Expand All @@ -106,7 +105,6 @@ public function testItCastsAModelsIntegerIdToAString(): void
'jsonapi' => [
'version' => '1.0',
],
'included' => [],
]);
$this->assertValidJsonApi($response);
}
Expand Down
3 changes: 3 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Orchestra\Testbench\TestCase as BaseTestCase;
use RuntimeException;

use TiMacDonald\JsonApi\JsonApiResource;
use function is_string;

class TestCase extends BaseTestCase
Expand All @@ -21,6 +22,8 @@ public function setUp(): void
{
parent::setUp();

JsonApiResource::resolveServerImplementationNormally();

$this->withoutExceptionHandling();
}

Expand Down

0 comments on commit 07f9afc

Please sign in to comment.