diff --git a/.gitattributes b/.gitattributes index 6374302..35d8020 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,11 @@ +# +# *.http files in /test/ are response fixtures and should have CRLF line endings +# +/test/Integration/responses/*.http text eol=crlf + +# +# Ignores +# /.cache/ export-ignore /.github/ export-ignore /.laminas-ci/ export-ignore diff --git a/src/BaseClient.php b/src/BaseClient.php index 1904ba7..dc4119e 100644 --- a/src/BaseClient.php +++ b/src/BaseClient.php @@ -188,4 +188,105 @@ private function send(RequestInterface $request): ResponseInterface return $response; } + + /** @inheritDoc */ + public function fetchAllSharedSlices(): iterable + { + $response = $this->send( + $this->request('GET', '/slices'), + ); + + $body = Json::decodeToArray((string) $response->getBody()); + $list = []; + foreach ($body as $item) { + Assert::isArray($item); + $definition = SharedSlice::fromArray($item); + $list[$definition->id] = $definition; + } + + return $list; + } + + public function createSharedSlice(SharedSlice $definition): void + { + $request = $this->request('POST', '/slices/insert') + ->withHeader('Content-Type', 'application/json') + ->withBody($this->streamFactory->createStream($definition->json)); + + $response = $this->send($request); + + if ($response->getStatusCode() === 400) { + throw InvalidDefinition::invalidSlice($request, $response); + } + + if ($response->getStatusCode() === 409) { + throw InsertFailed::forSlice($definition, $request, $response); + } + + if ($response->getStatusCode() !== 201) { + throw UnexpectedStatusCode::withExpectedCode(201, $request, $response); + } + } + + public function updateSharedSlice(SharedSlice $definition): void + { + $request = $this->request('POST', '/slices/update') + ->withHeader('Content-Type', 'application/json') + ->withBody($this->streamFactory->createStream($definition->json)); + + $response = $this->send($request); + + if ($response->getStatusCode() === 400) { + throw InvalidDefinition::invalidSlice($request, $response); + } + + if ($response->getStatusCode() === 422) { + throw UpdateFailed::forSlice($definition, $request, $response); + } + + if ($response->getStatusCode() !== 204) { + throw UnexpectedStatusCode::withExpectedCode(204, $request, $response); + } + } + + public function saveSharedSlice(SharedSlice $slice): void + { + try { + $current = $this->getSharedSlice($slice->id); + } catch (DefinitionNotFound) { + $this->createSharedSlice($slice); + + return; + } + + if ($slice->equals($current)) { + return; + } + + $this->updateSharedSlice($slice); + } + + public function getSharedSlice(string $id): SharedSlice + { + $request = $this->request('GET', sprintf('/slices/%s', $id)); + $response = $this->send($request); + + if ($response->getStatusCode() === 404) { + throw DefinitionNotFound::forSharedSlice($id, $request, $response); + } + + return SharedSlice::fromArray( + Json::decodeToArray((string) $response->getBody()), + ); + } + + public function deleteSharedSlice(string $id): void + { + $request = $this->request('DELETE', sprintf('/slices/%s', $id)); + $response = $this->send($request); + + if ($response->getStatusCode() !== 204) { + throw UnexpectedStatusCode::withExpectedCode(204, $request, $response); + } + } } diff --git a/src/Client.php b/src/Client.php index 92a0901..cafc8f4 100644 --- a/src/Client.php +++ b/src/Client.php @@ -13,6 +13,8 @@ interface Client /** * Retrieve a document type definition by its identifier * + * @param non-empty-string $id + * * @throws DefinitionNotFound if there is no such type with the given id. * @throws Exception if any errors occur communicating with the remote API. */ @@ -37,7 +39,42 @@ public function fetchAllDefinitions(): iterable; /** * Deletes the definition with the given identifier * + * @param non-empty-string $id + * * @throws Exception if any errors occur communicating with the remote API. */ public function deleteDefinition(string $id): void; + + /** + * Return a list of the Shared Slices found in the remote repo + * + * @return iterable&Countable + */ + public function fetchAllSharedSlices(): iterable; + + /** + * Insert or update a shared slice + * + * @throws Exception + */ + public function saveSharedSlice(SharedSlice $slice): void; + + /** + * Fetch a shared slice + * + * @param non-empty-string $id + * + * @throws DefinitionNotFound if there is no such type with the given id. + * @throws Exception if any errors occur communicating with the remote API. + */ + public function getSharedSlice(string $id): SharedSlice; + + /** + * Deletes the shared slice with the given identifier + * + * @param non-empty-string $id + * + * @throws Exception if any errors occur communicating with the remote API. + */ + public function deleteSharedSlice(string $id): void; } diff --git a/src/Definition.php b/src/Definition.php index 5ff1f6e..ffee436 100644 --- a/src/Definition.php +++ b/src/Definition.php @@ -10,6 +10,10 @@ /** @psalm-immutable */ final class Definition implements JsonSerializable { + /** + * @param non-empty-string $id + * @param non-empty-string $json + */ private function __construct( private string $id, private string $label, @@ -19,6 +23,10 @@ private function __construct( ) { } + /** + * @param non-empty-string $id + * @param non-empty-string $json + */ public static function new( string $id, string $label, @@ -66,6 +74,7 @@ public function jsonSerialize(): array ]; } + /** @return non-empty-string */ public function id(): string { return $this->id; @@ -86,11 +95,13 @@ public function isActive(): bool return $this->active; } + /** @return non-empty-string */ public function json(): string { return $this->json; } + /** @param non-empty-string $json */ public function withAlteredPayload(string $json): self { $clone = clone $this; diff --git a/src/Exception/DefinitionNotFound.php b/src/Exception/DefinitionNotFound.php index 20d7d74..e0f7a31 100644 --- a/src/Exception/DefinitionNotFound.php +++ b/src/Exception/DefinitionNotFound.php @@ -22,4 +22,16 @@ public static function withIdentifier( $response, ); } + + public static function forSharedSlice( + string $id, + RequestInterface $request, + ResponseInterface $response, + ): self { + return self::withHttpExchange( + sprintf('A shared slice with the id "%s" cannot be found', $id), + $request, + $response, + ); + } } diff --git a/src/Exception/InsertFailed.php b/src/Exception/InsertFailed.php index 7c6cf4b..17b715a 100644 --- a/src/Exception/InsertFailed.php +++ b/src/Exception/InsertFailed.php @@ -5,6 +5,7 @@ namespace Prismic\DocumentType\Exception; use Prismic\DocumentType\Definition; +use Prismic\DocumentType\SharedSlice; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -26,4 +27,19 @@ public static function withDefinition( $response, ); } + + public static function forSlice( + SharedSlice $definition, + RequestInterface $request, + ResponseInterface $response, + ): self { + return self::withHttpExchange( + sprintf( + 'Failed to insert the shared slice "%s" because one already exists with that identifier', + $definition->id, + ), + $request, + $response, + ); + } } diff --git a/src/Exception/InvalidDefinition.php b/src/Exception/InvalidDefinition.php index 962bb28..f8bc255 100644 --- a/src/Exception/InvalidDefinition.php +++ b/src/Exception/InvalidDefinition.php @@ -17,4 +17,13 @@ public static function new(RequestInterface $request, ResponseInterface $respons $response, ); } + + public static function invalidSlice(RequestInterface $request, ResponseInterface $response): self + { + return self::withHttpExchange( + 'The slice definition was rejected because it (most likely) has validation errors', + $request, + $response, + ); + } } diff --git a/src/Exception/UpdateFailed.php b/src/Exception/UpdateFailed.php index 76e57f7..8e2fd3d 100644 --- a/src/Exception/UpdateFailed.php +++ b/src/Exception/UpdateFailed.php @@ -5,6 +5,7 @@ namespace Prismic\DocumentType\Exception; use Prismic\DocumentType\Definition; +use Prismic\DocumentType\SharedSlice; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -26,4 +27,19 @@ public static function withDefinition( $response, ); } + + public static function forSlice( + SharedSlice $definition, + RequestInterface $request, + ResponseInterface $response, + ): self { + return self::withHttpExchange( + sprintf( + 'Failed to update the shared slice "%s" because it has not yet been created', + $definition->id, + ), + $request, + $response, + ); + } } diff --git a/src/Json.php b/src/Json.php index 924b4da..795f4ed 100644 --- a/src/Json.php +++ b/src/Json.php @@ -34,7 +34,11 @@ public static function decodeToArray(string $json): array } } - /** @param array $parameters */ + /** + * @param array $parameters + * + * @return non-empty-string + */ public static function encodeArray(array $parameters): string { try { diff --git a/src/SharedSlice.php b/src/SharedSlice.php new file mode 100644 index 0000000..41533b1 --- /dev/null +++ b/src/SharedSlice.php @@ -0,0 +1,44 @@ + $payload */ + public static function fromArray(array $payload): self + { + Assert::keyExists($payload, 'id'); + Assert::stringNotEmpty($payload['id']); + + return new self($payload['id'], json_encode($payload)); + } + + public function equals(SharedSlice $other): bool + { + return $this->id === $other->id + && $this->json === $other->json; + } +} diff --git a/test/Integration/BaseClientTest.php b/test/Integration/BaseClientTest.php index 8f7b584..d423549 100644 --- a/test/Integration/BaseClientTest.php +++ b/test/Integration/BaseClientTest.php @@ -6,6 +6,7 @@ use Laminas\Diactoros\StreamFactory; use Laminas\Diactoros\UriFactory; +use PHPUnit\Framework\Attributes\Depends; use Prismic\DocumentType\BaseClient; use Prismic\DocumentType\Definition; use Prismic\DocumentType\Exception\AuthenticationFailed; @@ -16,6 +17,7 @@ use Prismic\DocumentType\Exception\ResponseError; use Prismic\DocumentType\Exception\UnexpectedStatusCode; use Prismic\DocumentType\Exception\UpdateFailed; +use Prismic\DocumentType\SharedSlice; use Psr\Http\Client\ClientExceptionInterface; use Psr\Http\Message\RequestInterface; @@ -402,4 +404,170 @@ public function testThatAClientCanBeGeneratedForADifferentRepository(): void $header = $last->getHeaderLine('repository'); self::assertStringContainsString('new-repository', $header); } + + public function testSuccessfulFetchOfAllSlices(): void + { + $results = $this->client->fetchAllSharedSlices(); + self::assertGreaterThan(0, count($results)); + self::assertContainsOnlyInstancesOf(SharedSlice::class, $results); + foreach ($results as $key => $definition) { + self::assertEquals($definition->id, $key); + } + } + + public function testCreateSharedSlice(): void + { + $this->client->createSharedSlice(SharedSlice::new( + 'example-slice', + '{"id":"example-slice"}', + )); + + $last = $this->httpClient()->lastRequest(); + assert($last instanceof RequestInterface); + self::assertStringContainsString('/slices/insert', $last->getUri()->getPath()); + } + + public function testCreateDuplicateSharedSlice(): void + { + $this->expectException(InsertFailed::class); + $this->expectExceptionMessage('duplicate-slice'); + $this->client->createSharedSlice(SharedSlice::new( + 'duplicate-slice', + '{"id":"duplicate-slice"}', + )); + } + + public function testCreateInvalidSharedSlice(): void + { + $this->expectException(InvalidDefinition::class); + $this->expectExceptionMessage('slice definition was rejected'); + $this->client->createSharedSlice(SharedSlice::new( + 'invalid-slice', + '{"id":"invalid-slice"}', + )); + } + + public function testCreateSharedSliceWithUnexpectedResponse(): void + { + $this->expectException(UnexpectedStatusCode::class); + $this->client->createSharedSlice(SharedSlice::new( + 'unexpected', + '{"id":"unexpected"}', + )); + } + + public function testUpdateSharedSlice(): void + { + $this->client->updateSharedSlice(SharedSlice::new( + 'update', + '{"id":"update"}', + )); + + $last = $this->httpClient()->lastRequest(); + assert($last instanceof RequestInterface); + self::assertStringContainsString('/slices/update', $last->getUri()->getPath()); + } + + public function testUpdateSharedSliceWithInvalidSpec(): void + { + $this->expectException(InvalidDefinition::class); + $this->expectExceptionMessage('slice definition was rejected'); + $this->client->updateSharedSlice(SharedSlice::new( + 'update-invalid', + '{"id":"update-invalid"}', + )); + } + + public function testUpdateSharedSliceThatDoesNotExist(): void + { + $this->expectException(UpdateFailed::class); + $this->expectExceptionMessage('update-missing'); + $this->client->updateSharedSlice(SharedSlice::new( + 'update-missing', + '{"id":"update-missing"}', + )); + } + + public function testUpdateSliceWithUnexpectedResponse(): void + { + $this->expectException(UnexpectedStatusCode::class); + $this->client->updateSharedSlice(SharedSlice::new( + 'update-unexpected', + '{"id":"update-unexpected"}', + )); + } + + public function testGetSliceById(): SharedSlice + { + $slice = $this->client->getSharedSlice('example-slice'); + self::assertSame('example-slice', $slice->id); + + return $slice; + } + + public function testGetSliceWhenNotFound(): void + { + $this->expectException(DefinitionNotFound::class); + $this->expectExceptionMessage('not-found'); + $this->client->getSharedSlice('not-found'); + } + + #[Depends('testGetSliceById')] + public function testSaveDoesNothingWhenTheSliceHasNotChanged(SharedSlice $slice): void + { + $this->client->saveSharedSlice($slice); + + $last = $this->httpClient()->lastRequest(); + assert($last instanceof RequestInterface); + self::assertSame('GET', $last->getMethod()); + self::assertStringContainsString('/slices/example-slice', $last->getUri()->getPath()); + } + + public function testSaveUpdatesWhenTheSliceIsChanged(): void + { + $this->client->saveSharedSlice(SharedSlice::new( + 'example-slice', + '{"id":"example-slice", "was":"updated"}', + )); + + $last = $this->httpClient()->lastRequest(); + assert($last instanceof RequestInterface); + self::assertStringContainsString('/slices/update', $last->getUri()->getPath()); + } + + public function testSaveInsertsWhenTheSliceIsNotFound(): void + { + $this->client->saveSharedSlice(SharedSlice::new( + 'insert-save', + '{"id":"insert-save"}', + )); + + $last = $this->httpClient()->lastRequest(); + assert($last instanceof RequestInterface); + self::assertStringContainsString('/slices/insert', $last->getUri()->getPath()); + } + + public function testDeleteSharedSlice(): void + { + $this->client->deleteSharedSlice('delete-me'); + + $last = $this->httpClient()->lastRequest(); + assert($last instanceof RequestInterface); + self::assertSame('DELETE', $last->getMethod()); + self::assertStringContainsString('/slices/delete-me', $last->getUri()->getPath()); + } + + public function testDeleteWithUnexpectedResponse(): void + { + try { + $this->client->deleteSharedSlice('delete-weird'); + self::fail('Exception expected'); + } catch (UnexpectedStatusCode) { + } + + $last = $this->httpClient()->lastRequest(); + assert($last instanceof RequestInterface); + self::assertSame('DELETE', $last->getMethod()); + self::assertStringContainsString('/slices/delete-weird', $last->getUri()->getPath()); + } } diff --git a/test/Integration/MockServer.php b/test/Integration/MockServer.php index edc12ab..ac40d35 100644 --- a/test/Integration/MockServer.php +++ b/test/Integration/MockServer.php @@ -18,6 +18,8 @@ use function strpos; use function strtoupper; +use const PHP_EOL; + final class MockServer { public const VALID_TOKEN = 'Valid Token'; @@ -52,16 +54,6 @@ public function stop(): void } private function handleRequest(RequestInterface $request): ResponseInterface - { - $response = self::match($request); - if (! $response) { - return new TextResponse('Invalid Request', 500); - } - - return $response; - } - - private static function match(RequestInterface $request): ResponseInterface|null { $responses = [ [ @@ -148,6 +140,113 @@ private static function match(RequestInterface $request): ResponseInterface|null 'path' => '/customtypes/403', 'file' => __DIR__ . '/responses/403.http', ], + // Slices + [ + 'method' => 'GET', + 'token' => self::VALID_TOKEN, + 'path' => '/slices', + 'file' => __DIR__ . '/responses/GET.slices.http', + ], + [ + 'method' => 'POST', + 'token' => self::VALID_TOKEN, + 'path' => '/slices/insert', + 'file' => __DIR__ . '/responses/POST.slices-insert.http', + 'body' => static fn (string $body): bool => strpos($body, '"id":"example-slice"') !== false, + ], + [ + 'method' => 'POST', + 'token' => self::VALID_TOKEN, + 'path' => '/slices/insert', + 'file' => __DIR__ . '/responses/POST.slices-insert.duplicate.http', + 'body' => static fn (string $body): bool => strpos($body, '"id":"duplicate-slice"') !== false, + ], + [ + 'method' => 'POST', + 'token' => self::VALID_TOKEN, + 'path' => '/slices/insert', + 'file' => __DIR__ . '/responses/POST.slices-insert.invalid.http', + 'body' => static fn (string $body): bool => strpos($body, '"id":"invalid-slice"') !== false, + ], + [ + 'method' => 'POST', + 'token' => self::VALID_TOKEN, + 'path' => '/slices/insert', + 'file' => __DIR__ . '/responses/POST.slices-insert.unexpected.http', + 'body' => static fn (string $body): bool => strpos($body, '"id":"unexpected"') !== false, + ], + [ + 'method' => 'POST', + 'token' => self::VALID_TOKEN, + 'path' => '/slices/update', + 'file' => __DIR__ . '/responses/POST.slices-update.http', + 'body' => static fn (string $body): bool => strpos($body, '"id":"update"') !== false, + ], + [ + 'method' => 'POST', + 'token' => self::VALID_TOKEN, + 'path' => '/slices/update', + 'file' => __DIR__ . '/responses/POST.slices-insert.invalid.http', + 'body' => static fn (string $body): bool => strpos($body, '"id":"update-invalid"') !== false, + ], + [ + 'method' => 'POST', + 'token' => self::VALID_TOKEN, + 'path' => '/slices/update', + 'file' => __DIR__ . '/responses/POST.slices-update.not-found.http', + 'body' => static fn (string $body): bool => strpos($body, '"id":"update-missing"') !== false, + ], + [ + 'method' => 'POST', + 'token' => self::VALID_TOKEN, + 'path' => '/slices/update', + 'file' => __DIR__ . '/responses/POST.slices-insert.unexpected.http', + 'body' => static fn (string $body): bool => strpos($body, '"id":"update-unexpected"') !== false, + ], + [ + 'method' => 'GET', + 'token' => self::VALID_TOKEN, + 'path' => '/slices/example-slice', + 'file' => __DIR__ . '/responses/GET.slice.example.http', + ], + [ + 'method' => 'GET', + 'token' => self::VALID_TOKEN, + 'path' => '/slices/not-found', + 'file' => __DIR__ . '/responses/GET.slices.not-found.http', + ], + [ + 'method' => 'POST', + 'token' => self::VALID_TOKEN, + 'path' => '/slices/update', + 'file' => __DIR__ . '/responses/POST.slices-update.http', + 'body' => static fn (string $body): bool => strpos($body, '"was":"updated"') !== false, + ], + [ + 'method' => 'GET', + 'token' => self::VALID_TOKEN, + 'path' => '/slices/insert-save', + 'file' => __DIR__ . '/responses/GET.slices.not-found.http', + ], + [ + 'method' => 'POST', + 'token' => self::VALID_TOKEN, + 'path' => '/slices/insert', + 'file' => __DIR__ . '/responses/POST.slices-insert.http', + 'body' => static fn (string $body): bool => strpos($body, '"id":"insert-save"') !== false, + ], + [ + 'method' => 'DELETE', + 'token' => self::VALID_TOKEN, + 'path' => '/slices/delete-me', + 'file' => __DIR__ . '/responses/DELETE.slices.http', + ], + [ + 'method' => 'DELETE', + 'token' => self::VALID_TOKEN, + 'path' => '/slices/delete-weird', + 'file' => __DIR__ . '/responses/POST.slices-insert.unexpected.http', + ], ]; $match = null; @@ -182,7 +281,7 @@ private static function match(RequestInterface $request): ResponseInterface|null } if (! $match) { - return null; + return new TextResponse('The request did not match any fixtures' . PHP_EOL, 999); } return Serializer::fromString(file_get_contents($match['file'])); diff --git a/test/Integration/responses/DELETE.slices.http b/test/Integration/responses/DELETE.slices.http new file mode 100644 index 0000000..334b7de --- /dev/null +++ b/test/Integration/responses/DELETE.slices.http @@ -0,0 +1,5 @@ +HTTP/1.1 204 No Content +Content-Type: application/json +Content-Length: 0 +Connection: close +Date: Wed, 30 Oct 2024 14:57:58 GMT diff --git a/test/Integration/responses/GET.customtypes.http b/test/Integration/responses/GET.customtypes.http index bcbf9ef..6db6e98 100644 --- a/test/Integration/responses/GET.customtypes.http +++ b/test/Integration/responses/GET.customtypes.http @@ -1,11 +1,11 @@ -HTTP/1.1 200 OK -Content-Type: application/json -Content-Length: 156 -Connection: close -Date: Fri, 06 Aug 2021 22:36:55 GMT -Access-Control-Allow-Origin: * -Access-Control-Allow-Headers: Content-Type,repository,Authorization -Access-Control-Allow-Methods: OPTIONS,POST,GET -Access-Control-Allow-Credentials: true - -[{"id":"example","label":"Example","repeatable":true,"json":{"Main":{"value":{"type":"Number","config":{"label":"Value","min":0,"max":10}}}},"status":true}] +HTTP/1.1 200 OK +Content-Type: application/json +Content-Length: 156 +Connection: close +Date: Fri, 06 Aug 2021 22:36:55 GMT +Access-Control-Allow-Origin: * +Access-Control-Allow-Headers: Content-Type,repository,Authorization +Access-Control-Allow-Methods: OPTIONS,POST,GET +Access-Control-Allow-Credentials: true + +[{"id":"example","label":"Example","repeatable":true,"json":{"Main":{"value":{"type":"Number","config":{"label":"Value","min":0,"max":10}}}},"status":true}] diff --git a/test/Integration/responses/GET.slice.example.http b/test/Integration/responses/GET.slice.example.http new file mode 100644 index 0000000..aea8726 --- /dev/null +++ b/test/Integration/responses/GET.slice.example.http @@ -0,0 +1,7 @@ +HTTP/1.1 200 OK +Content-Type: application/json +Content-Length: 423 +Connection: close +Date: Wed, 30 Oct 2024 11:48:19 GMT + +{"id":"example-slice","type":"SharedSlice","name":"Example Slice","description":"An example of a shared slice","variations":[{"id":"default","name":"Default","docURL":"","version":"","description":"The default variant","primary":{"text":{"type":"Number","config":{"min":0,"max":10}}},"items":{},"imageUrl":"https://images.prismic.io/slice-machine/621a5ec4-0387-4bc5-9860-2dd46cbc07cd_default_ss.png?auto=compress,format"}]} diff --git a/test/Integration/responses/GET.slices.http b/test/Integration/responses/GET.slices.http new file mode 100644 index 0000000..abfee19 --- /dev/null +++ b/test/Integration/responses/GET.slices.http @@ -0,0 +1,7 @@ +HTTP/1.1 200 OK +Content-Type: application/json +Content-Length: 425 +Connection: close +Date: Wed, 30 Oct 2024 11:24:16 GMT + +[{"id":"example-slice","type":"SharedSlice","name":"Example Slice","description":"An example of a shared slice","variations":[{"id":"default","name":"Default","docURL":"","version":"","description":"The default variant","primary":{"text":{"type":"Number","config":{"min":0,"max":10}}},"items":{},"imageUrl":"https://images.prismic.io/slice-machine/621a5ec4-0387-4bc5-9860-2dd46cbc07cd_default_ss.png?auto=compress,format"}]}] diff --git a/test/Integration/responses/GET.slices.not-found.http b/test/Integration/responses/GET.slices.not-found.http new file mode 100644 index 0000000..2269434 --- /dev/null +++ b/test/Integration/responses/GET.slices.not-found.http @@ -0,0 +1,5 @@ +HTTP/1.1 404 Not Found +Content-Type: application/json +Content-Length: 0 +Connection: close +Date: Wed, 30 Oct 2024 11:18:41 GMT diff --git a/test/Integration/responses/POST.slices-insert.duplicate.http b/test/Integration/responses/POST.slices-insert.duplicate.http new file mode 100644 index 0000000..782f6f2 --- /dev/null +++ b/test/Integration/responses/POST.slices-insert.duplicate.http @@ -0,0 +1,11 @@ +HTTP/1.1 409 Conflict +Content-Type: application/json +Content-Length: 33 +Connection: close +Date: Tue, 31 Aug 2021 21:54:56 GMT +Access-Control-Allow-Origin: * +Access-Control-Allow-Headers: Content-Type,repository,Authorization +Access-Control-Allow-Methods: OPTIONS,POST,GET +Access-Control-Allow-Credentials: true + +CONFLICT: example already exists. diff --git a/test/Integration/responses/POST.slices-insert.http b/test/Integration/responses/POST.slices-insert.http new file mode 100644 index 0000000..2b7daaf --- /dev/null +++ b/test/Integration/responses/POST.slices-insert.http @@ -0,0 +1,9 @@ +HTTP/1.1 201 Created +Content-Type: application/json +Content-Length: 0 +Connection: close +Date: Tue, 31 Aug 2021 23:04:24 GMT +Access-Control-Allow-Origin: * +Access-Control-Allow-Headers: Content-Type,repository,Authorization +Access-Control-Allow-Methods: OPTIONS,POST,GET +Access-Control-Allow-Credentials: true diff --git a/test/Integration/responses/POST.slices-insert.invalid.http b/test/Integration/responses/POST.slices-insert.invalid.http new file mode 100644 index 0000000..ca9d475 --- /dev/null +++ b/test/Integration/responses/POST.slices-insert.invalid.http @@ -0,0 +1,14 @@ +HTTP/1.1 400 Bad Request +Content-Type: application/json +Content-Length: 124 +Connection: close +Date: Wed, 30 Oct 2024 12:14:35 GMT +X-Cache: Error from cloudfront + + +Invalid Paths: +PATH: |0|/variations|0||0|/docURL +VALUE: undefined + +PATH: |0|/variations|0||0|/version +VALUE: undefined diff --git a/test/Integration/responses/POST.slices-insert.unexpected.http b/test/Integration/responses/POST.slices-insert.unexpected.http new file mode 100644 index 0000000..05444da --- /dev/null +++ b/test/Integration/responses/POST.slices-insert.unexpected.http @@ -0,0 +1,11 @@ +HTTP/1.1 499 Fucked +Content-Type: application/json +Content-Length: 33 +Connection: close +Date: Tue, 31 Aug 2021 21:54:56 GMT +Access-Control-Allow-Origin: * +Access-Control-Allow-Headers: Content-Type,repository,Authorization +Access-Control-Allow-Methods: OPTIONS,POST,GET +Access-Control-Allow-Credentials: true + +Fucked: Some random response. Oh look. It _is_ JSON really. diff --git a/test/Integration/responses/POST.slices-update.http b/test/Integration/responses/POST.slices-update.http new file mode 100644 index 0000000..894b4a0 --- /dev/null +++ b/test/Integration/responses/POST.slices-update.http @@ -0,0 +1,9 @@ +HTTP/1.1 204 No Content +Content-Type: application/json +Content-Length: 0 +Connection: close +Date: Tue, 31 Aug 2021 22:28:15 GMT +Access-Control-Allow-Origin: * +Access-Control-Allow-Headers: Content-Type,repository,Authorization +Access-Control-Allow-Methods: OPTIONS,POST,GET +Access-Control-Allow-Credentials: true diff --git a/test/Integration/responses/POST.slices-update.not-found.http b/test/Integration/responses/POST.slices-update.not-found.http new file mode 100644 index 0000000..125204f --- /dev/null +++ b/test/Integration/responses/POST.slices-update.not-found.http @@ -0,0 +1,11 @@ +HTTP/1.1 422 +Content-Type: application/json +Content-Length: 36 +Connection: close +Date: Tue, 31 Aug 2021 22:33:01 GMT +Access-Control-Allow-Origin: * +Access-Control-Allow-Headers: Content-Type,repository,Authorization +Access-Control-Allow-Methods: OPTIONS,POST,GET +Access-Control-Allow-Credentials: true + +not-found-for-update does not exist. diff --git a/test/Unit/JsonTest.php b/test/Unit/JsonTest.php index e30faca..f1873fd 100644 --- a/test/Unit/JsonTest.php +++ b/test/Unit/JsonTest.php @@ -94,9 +94,9 @@ public function testMaxDepthExceeded(): void public function testMaxDepthNotExceeded(): void { - $inputArray = $this->arrayWithDepth(511); + $inputArray = $this->arrayWithDepth(200); - $json = json_encode($inputArray, JSON_THROW_ON_ERROR, 513); + $json = json_encode($inputArray, JSON_THROW_ON_ERROR, 201); self::assertEquals($inputArray, Json::decodeToArray($json)); }