From a4d699f708894356191b50be7f277e7275a93e6d Mon Sep 17 00:00:00 2001 From: Sammyjo20 <29132017+Sammyjo20@users.noreply.github.com> Date: Wed, 20 Sep 2023 22:41:41 +0100 Subject: [PATCH] Feature | v3 - Add middleware back to body --- src/Contracts/Body/BodyRepository.php | 9 +------ src/Helpers/FixtureHelper.php | 2 +- src/Helpers/URLHelper.php | 2 +- src/Http/PendingRequest/MergeBody.php | 2 +- src/Http/Response.php | 2 -- src/Repositories/Body/ArrayBodyRepository.php | 19 +++++++-------- src/Repositories/Body/FormBodyRepository.php | 2 +- src/Repositories/Body/JsonBodyRepository.php | 2 +- .../Body/MultipartBodyRepository.php | 22 +++++++---------- .../Body/StreamBodyRepository.php | 6 +---- .../Body/StringBodyRepository.php | 12 +--------- tests/Feature/Body/HasFormBodyTest.php | 2 +- tests/Feature/Body/HasJsonBodyTest.php | 8 +++---- tests/Feature/Body/HasMultipartBodyTest.php | 8 +++---- tests/Feature/Body/HasStreamBodyTest.php | 2 +- tests/Feature/Body/HasStringBodyTest.php | 2 +- tests/Feature/Body/HasXmlBodyTest.php | 2 +- .../ClientCredentialsFlowConnectorTest.php | 8 +++---- tests/Feature/PoolTest.php | 2 +- tests/Unit/Body/ArrayBodyRepositoryTest.php | 24 +++++++++---------- .../Unit/Body/MultipartBodyRepositoryTest.php | 18 +++++++------- tests/Unit/Body/StreamBodyRepositoryTest.php | 2 ++ tests/Unit/Body/StringBodyRepositoryTest.php | 8 +++---- tests/Unit/MockResponseTest.php | 2 +- 24 files changed, 70 insertions(+), 98 deletions(-) diff --git a/src/Contracts/Body/BodyRepository.php b/src/Contracts/Body/BodyRepository.php index b165e7a5..bd0dba38 100644 --- a/src/Contracts/Body/BodyRepository.php +++ b/src/Contracts/Body/BodyRepository.php @@ -17,17 +17,10 @@ interface BodyRepository public function set(mixed $value): static; /** - * Retrieve the raw data in the repository. + * Get the raw data in the repository. */ public function all(): mixed; - /** - * Retrieve the raw data in the repository - * - * Alias of `all()`. - */ - public function get(): mixed; - /** * Determine if the repository is empty */ diff --git a/src/Helpers/FixtureHelper.php b/src/Helpers/FixtureHelper.php index 979bb47f..22c7620f 100644 --- a/src/Helpers/FixtureHelper.php +++ b/src/Helpers/FixtureHelper.php @@ -7,7 +7,7 @@ /** * @internal */ -final class FixtureHelper +class FixtureHelper { /** * Recursively replaces array attributes diff --git a/src/Helpers/URLHelper.php b/src/Helpers/URLHelper.php index 902f4028..1e93f8e3 100644 --- a/src/Helpers/URLHelper.php +++ b/src/Helpers/URLHelper.php @@ -7,7 +7,7 @@ /** * @internal */ -final class URLHelper +class URLHelper { /** * Check if a URL matches a given pattern diff --git a/src/Http/PendingRequest/MergeBody.php b/src/Http/PendingRequest/MergeBody.php index 3c40dd17..bfe883c4 100644 --- a/src/Http/PendingRequest/MergeBody.php +++ b/src/Http/PendingRequest/MergeBody.php @@ -51,7 +51,7 @@ public function __invoke(PendingRequest $pendingRequest): PendingRequest // We'll clone the request body into the connector body so any properties on the request // body will take priority if they are using a keyed array. - $body = $repository->merge($requestBody->get()); + $body = $repository->merge($requestBody->all()); } // Now we'll check if the body is a MultipartBodyRepository. If it is, then we must diff --git a/src/Http/Response.php b/src/Http/Response.php index 9ff72336..c935a6d3 100644 --- a/src/Http/Response.php +++ b/src/Http/Response.php @@ -109,8 +109,6 @@ public function getConnector(): Connector /** * Get the original request that created the response. - * - * @deprecated Will be removed in Saloon v4. Use $response->getPendingRequest()->getRequest() instead. */ public function getRequest(): Request { diff --git a/src/Repositories/Body/ArrayBodyRepository.php b/src/Repositories/Body/ArrayBodyRepository.php index 2f9c8872..f63fba67 100644 --- a/src/Repositories/Body/ArrayBodyRepository.php +++ b/src/Repositories/Body/ArrayBodyRepository.php @@ -79,18 +79,13 @@ public function add(string|int|null $key = null, mixed $value = null): static } /** - * Get a specific key of the array + * Get the raw data in the repository. * - * @param array-key|null $key - * @return ($key is null ? array : mixed) + * @return array */ - public function all(string|int|null $key = null, mixed $default = null): mixed + public function all(): array { - if (is_null($key)) { - return $this->data; - } - - return $this->data[$key] ?? $default; + return $this->data; } /** @@ -103,7 +98,11 @@ public function all(string|int|null $key = null, mixed $default = null): mixed */ public function get(string|int|null $key = null, mixed $default = null): mixed { - return $this->all($key, $default); + if (is_null($key)) { + return $this->all(); + } + + return $this->all()[$key] ?? $default; } /** diff --git a/src/Repositories/Body/FormBodyRepository.php b/src/Repositories/Body/FormBodyRepository.php index a079bca7..169b8de0 100644 --- a/src/Repositories/Body/FormBodyRepository.php +++ b/src/Repositories/Body/FormBodyRepository.php @@ -16,6 +16,6 @@ class FormBodyRepository extends ArrayBodyRepository implements Stringable */ public function __toString(): string { - return http_build_query($this->get()); + return http_build_query($this->all()); } } diff --git a/src/Repositories/Body/JsonBodyRepository.php b/src/Repositories/Body/JsonBodyRepository.php index 815add6b..05b1ea25 100644 --- a/src/Repositories/Body/JsonBodyRepository.php +++ b/src/Repositories/Body/JsonBodyRepository.php @@ -45,7 +45,7 @@ public function getJsonFlags(): int */ public function __toString(): string { - $json = json_encode($this->get(), $this->getJsonFlags()); + $json = json_encode($this->all(), $this->getJsonFlags()); return $json === false ? '' : $json; } diff --git a/src/Repositories/Body/MultipartBodyRepository.php b/src/Repositories/Body/MultipartBodyRepository.php index e9cf0040..c5fe470a 100644 --- a/src/Repositories/Body/MultipartBodyRepository.php +++ b/src/Repositories/Body/MultipartBodyRepository.php @@ -111,29 +111,23 @@ public function attach(MultipartValue $file): static } /** - * Get a specific key of the array + * Get the raw data in the repository. * - * @return ($key is null ? array : mixed) + * @return array<\Saloon\Data\MultipartValue> */ - public function all(string|int $key = null, mixed $default = null): mixed + public function all(): array { - if (is_null($key)) { - return $this->data->get(); - } - - return $this->data->get($key, $default); + return $this->data->all(); } /** * Get a specific key of the array * - * Alias of `all()`. - * - * @return ($key is null ? array : mixed) + * @param array-key $key */ - public function get(string|int $key = null, mixed $default = null): mixed + public function get(string|int $key, mixed $default = null): MultipartValue { - return $this->all($key, $default); + return $this->data->get($key, $default); } /** @@ -210,6 +204,6 @@ public function toStream(StreamFactoryInterface $streamFactory): StreamInterface throw new BodyException('Unable to create a multipart body stream because the multipart body factory was not set.'); } - return $this->multipartBodyFactory->create($streamFactory, (array)$this->get(), $this->getBoundary()); + return $this->multipartBodyFactory->create($streamFactory, $this->all(), $this->getBoundary()); } } diff --git a/src/Repositories/Body/StreamBodyRepository.php b/src/Repositories/Body/StreamBodyRepository.php index e7e0a940..75363251 100644 --- a/src/Repositories/Body/StreamBodyRepository.php +++ b/src/Repositories/Body/StreamBodyRepository.php @@ -50,8 +50,6 @@ public function set(mixed $value): static /** * Retrieve the stream from the repository - * - * @return StreamInterface|resource|null */ public function all(): mixed { @@ -61,9 +59,7 @@ public function all(): mixed /** * Retrieve the stream from the repository * - * Alias of `all()`. - * - * @return StreamInterface|resource|null + * Alias of "all" method. */ public function get(): mixed { diff --git a/src/Repositories/Body/StringBodyRepository.php b/src/Repositories/Body/StringBodyRepository.php index ff49191a..7b55b635 100644 --- a/src/Repositories/Body/StringBodyRepository.php +++ b/src/Repositories/Body/StringBodyRepository.php @@ -48,16 +48,6 @@ public function all(): ?string return $this->data; } - /** - * Retrieve all in the repository - * - * Alias of `all()`. - */ - public function get(): ?string - { - return $this->all(); - } - /** * Determine if the repository is empty */ @@ -79,6 +69,6 @@ public function isNotEmpty(): bool */ public function __toString(): string { - return $this->get() ?? ''; + return $this->all() ?? ''; } } diff --git a/tests/Feature/Body/HasFormBodyTest.php b/tests/Feature/Body/HasFormBodyTest.php index e69ecf5d..63f7f0d8 100644 --- a/tests/Feature/Body/HasFormBodyTest.php +++ b/tests/Feature/Body/HasFormBodyTest.php @@ -13,7 +13,7 @@ test('the default body is loaded with the content type header', function () { $request = new HasFormBodyRequest(); - expect($request->body()->get())->toEqual([ + expect($request->body()->all())->toEqual([ 'name' => 'Sam', 'catchphrase' => 'Yeehaw!', ]); diff --git a/tests/Feature/Body/HasJsonBodyTest.php b/tests/Feature/Body/HasJsonBodyTest.php index 1b38bd6f..acf8180a 100644 --- a/tests/Feature/Body/HasJsonBodyTest.php +++ b/tests/Feature/Body/HasJsonBodyTest.php @@ -17,7 +17,7 @@ test('the default body is loaded with the content type header', function () { $request = new HasJsonBodyRequest(); - expect($request->body()->get())->toEqual([ + expect($request->body()->all())->toEqual([ 'name' => 'Sam', 'catchphrase' => 'Yeehaw!', ]); @@ -43,12 +43,12 @@ $connector = new HasJsonBodyConnector; $request = new HasJsonBodyRequest; - expect($connector->body()->get())->toEqual([ + expect($connector->body()->all())->toEqual([ 'name' => 'Gareth', 'drink' => 'Moonshine', ]); - expect($request->body()->get())->toEqual([ + expect($request->body()->all())->toEqual([ 'name' => 'Sam', 'catchphrase' => 'Yeehaw!', ]); @@ -60,7 +60,7 @@ expect($pendingRequestBody)->toBeInstanceOf(JsonBodyRepository::class); - expect($pendingRequestBody->get())->toEqual([ + expect($pendingRequestBody->all())->toEqual([ 'drink' => 'Moonshine', 'name' => 'Sam', 'catchphrase' => 'Yeehaw!', diff --git a/tests/Feature/Body/HasMultipartBodyTest.php b/tests/Feature/Body/HasMultipartBodyTest.php index 0bf88b40..3517658b 100644 --- a/tests/Feature/Body/HasMultipartBodyTest.php +++ b/tests/Feature/Body/HasMultipartBodyTest.php @@ -16,7 +16,7 @@ test('the default body is loaded with the content type header', function () { $request = new HasMultipartBodyRequest(); - expect($request->body()->get())->toEqual([ + expect($request->body()->all())->toEqual([ 'nickname' => new MultipartValue('nickname', 'Sam', 'user.txt', ['X-Saloon' => 'Yee-haw!']), ]); @@ -33,12 +33,12 @@ $connector = new HasMultipartBodyConnector; $request = new HasMultipartBodyRequest; - expect($connector->body()->get())->toEqual([ + expect($connector->body()->all())->toEqual([ 'nickname' => new MultipartValue('nickname', 'Gareth', 'user.txt', ['X-Saloon' => 'Yee-haw!']), 'drink' => new MultipartValue('drink', 'Moonshine', 'moonshine.txt', ['X-My-Head' => 'Spinning!']), ]); - expect($request->body()->get())->toEqual([ + expect($request->body()->all())->toEqual([ 'nickname' => new MultipartValue('nickname', 'Sam', 'user.txt', ['X-Saloon' => 'Yee-haw!']), ]); @@ -49,7 +49,7 @@ expect($pendingRequestBody)->toBeInstanceOf(MultipartBodyRepository::class); - expect($pendingRequestBody->get())->toEqual([ + expect($pendingRequestBody->all())->toEqual([ 'nickname' => new MultipartValue('nickname', 'Sam', 'user.txt', ['X-Saloon' => 'Yee-haw!']), 'drink' => new MultipartValue('drink', 'Moonshine', 'moonshine.txt', ['X-My-Head' => 'Spinning!']), ]); diff --git a/tests/Feature/Body/HasStreamBodyTest.php b/tests/Feature/Body/HasStreamBodyTest.php index 0706bb76..4a9a55ab 100644 --- a/tests/Feature/Body/HasStreamBodyTest.php +++ b/tests/Feature/Body/HasStreamBodyTest.php @@ -12,7 +12,7 @@ test('the default body is loaded', function () { $request = new HasStreamBodyRequest; - expect($request->body()->get())->toBeResource(); + expect($request->body()->all())->toBeResource(); }); test('the guzzle sender properly sends it', function () { diff --git a/tests/Feature/Body/HasStringBodyTest.php b/tests/Feature/Body/HasStringBodyTest.php index 9c056ea3..41461e44 100644 --- a/tests/Feature/Body/HasStringBodyTest.php +++ b/tests/Feature/Body/HasStringBodyTest.php @@ -12,7 +12,7 @@ test('the default body is loaded', function () { $request = new HasStringBodyRequest(); - expect($request->body()->get())->toEqual('name: Sam'); + expect($request->body()->all())->toEqual('name: Sam'); }); test('the guzzle sender properly sends it', function () { diff --git a/tests/Feature/Body/HasXmlBodyTest.php b/tests/Feature/Body/HasXmlBodyTest.php index c811ced6..352b9a38 100644 --- a/tests/Feature/Body/HasXmlBodyTest.php +++ b/tests/Feature/Body/HasXmlBodyTest.php @@ -13,7 +13,7 @@ test('the default body is loaded with the content type header', function () { $request = new HasXmlBodyRequest(); - expect($request->body()->get())->toEqual('

Howdy

'); + expect($request->body()->all())->toEqual('

Howdy

'); $connector = new TestConnector; $pendingRequest = $connector->createPendingRequest($request); diff --git a/tests/Feature/Oauth2/ClientCredentialsFlowConnectorTest.php b/tests/Feature/Oauth2/ClientCredentialsFlowConnectorTest.php index 23f329e4..081e8fef 100644 --- a/tests/Feature/Oauth2/ClientCredentialsFlowConnectorTest.php +++ b/tests/Feature/Oauth2/ClientCredentialsFlowConnectorTest.php @@ -31,7 +31,7 @@ $mockClient->assertSentCount(1); - expect($mockClient->getLastPendingRequest()->body()->get())->toEqual([ + expect($mockClient->getLastPendingRequest()->body()->all())->toEqual([ 'grant_type' => 'client_credentials', 'client_id' => 'client-id', 'client_secret' => 'client-secret', @@ -94,7 +94,7 @@ $mockClient->assertSentCount(1); - expect($mockClient->getLastPendingRequest()->body()->get())->toEqual([ + expect($mockClient->getLastPendingRequest()->body()->all())->toEqual([ 'grant_type' => 'client_credentials', 'client_id' => 'client-id', 'client_secret' => 'client-secret', @@ -120,7 +120,7 @@ $mockClient->assertSentCount(1); - expect($mockClient->getLastPendingRequest()->body()->get())->toEqual([ + expect($mockClient->getLastPendingRequest()->body()->all())->toEqual([ 'grant_type' => 'client_credentials', 'client_id' => 'client-id', 'client_secret' => 'client-secret', @@ -146,7 +146,7 @@ $mockClient->assertSentCount(1); - expect($mockClient->getLastPendingRequest()->body()->get())->toEqual([ + expect($mockClient->getLastPendingRequest()->body()->all())->toEqual([ 'grant_type' => 'client_credentials', 'client_id' => 'client-id', 'client_secret' => 'client-secret', diff --git a/tests/Feature/PoolTest.php b/tests/Feature/PoolTest.php index 9057d170..47a6efe0 100644 --- a/tests/Feature/PoolTest.php +++ b/tests/Feature/PoolTest.php @@ -117,7 +117,7 @@ $pool->withResponseHandler(function (Response $response) use (&$successCount, $mockResponses) { expect($response)->toBeInstanceOf(Response::class); - expect($response->json())->toEqual($mockResponses[$successCount]->body()->get()); + expect($response->json())->toEqual($mockResponses[$successCount]->body()->all()); $successCount++; }); diff --git a/tests/Unit/Body/ArrayBodyRepositoryTest.php b/tests/Unit/Body/ArrayBodyRepositoryTest.php index cd238ce9..df1614ce 100644 --- a/tests/Unit/Body/ArrayBodyRepositoryTest.php +++ b/tests/Unit/Body/ArrayBodyRepositoryTest.php @@ -8,7 +8,7 @@ test('the store is empty by default', function () { $body = new ArrayBodyRepository(); - expect($body->get())->toEqual([]); + expect($body->all())->toEqual([]); }); test('the store can have an array provided', function () { @@ -17,7 +17,7 @@ 'sidekick' => 'Mantas', ]); - expect($body->get())->toEqual([ + expect($body->all())->toEqual([ 'name' => 'Sam', 'sidekick' => 'Mantas', ]); @@ -28,7 +28,7 @@ $body->set(['name' => 'Sam']); - expect($body->get())->toEqual(['name' => 'Sam']); + expect($body->all())->toEqual(['name' => 'Sam']); }); test('it will throw an exception if you set a non-array', function () { @@ -44,7 +44,7 @@ $body->add('name', 'Sam'); - expect($body->get())->toEqual(['name' => 'Sam']); + expect($body->all())->toEqual(['name' => 'Sam']); }); test('you can add an item with an integer key', function () { @@ -52,7 +52,7 @@ $body->add(1, 'Sam'); - expect($body->get())->toEqual([1 => 'Sam']); + expect($body->all())->toEqual([1 => 'Sam']); }); test('you can add an item without a key', function () { @@ -60,7 +60,7 @@ $body->add(null, 'Sam'); - expect($body->get())->toEqual(['Sam']); + expect($body->all())->toEqual(['Sam']); }); test('you can conditionally add items to the array store', function () { @@ -71,7 +71,7 @@ $body->when(true, fn (ArrayBodyRepository $body) => $body->add('sidekick', 'Mantas')); $body->when(false, fn (ArrayBodyRepository $body) => $body->add('sidekick', 'Teo')); - expect($body->get())->toEqual(['name' => 'Gareth', 'sidekick' => 'Mantas']); + expect($body->all())->toEqual(['name' => 'Gareth', 'sidekick' => 'Mantas']); }); test('you can delete an item', function () { @@ -80,7 +80,7 @@ $body->add('name', 'Sam'); $body->remove('name'); - expect($body->get())->toEqual([]); + expect($body->all())->toEqual([]); }); test('you can delete an item with an integer key', function () { @@ -89,7 +89,7 @@ $body->add(1, 'Sam'); $body->remove(1); - expect($body->get())->toEqual([]); + expect($body->all())->toEqual([]); }); test('you can get an item', function () { @@ -101,7 +101,7 @@ // When omitting the key it should act like `->all()` - expect($body->get())->toEqual(['name' => 'Sam']); + expect($body->all())->toEqual(['name' => 'Sam']); }); test('you can get an item with an integer key', function () { @@ -121,7 +121,7 @@ $allResults = ['name' => 'Sam', 'superhero' => 'Iron Man']; expect($body->all())->toEqual($allResults); - expect($body->get())->toEqual($allResults); + expect($body->all())->toEqual($allResults); }); test('you can merge items together into the body repository', function () { @@ -134,7 +134,7 @@ $body->merge(['sidekick' => 'Gareth'], ['superhero' => 'Black Widow']); - expect($body->get())->toEqual(['name' => 'Sam', 'sidekick' => 'Gareth', 'superhero' => 'Black Widow']); + expect($body->all())->toEqual(['name' => 'Sam', 'sidekick' => 'Gareth', 'superhero' => 'Black Widow']); }); test('you can check if the store is empty or not', function () { diff --git a/tests/Unit/Body/MultipartBodyRepositoryTest.php b/tests/Unit/Body/MultipartBodyRepositoryTest.php index 8b6e3a6c..bf583e48 100644 --- a/tests/Unit/Body/MultipartBodyRepositoryTest.php +++ b/tests/Unit/Body/MultipartBodyRepositoryTest.php @@ -9,7 +9,7 @@ test('the store is empty by default', function () { $body = new MultipartBodyRepository(); - expect($body->get())->toEqual([]); + expect($body->all())->toEqual([]); }); test('the store can have an array of multipart values provided', function () { @@ -18,7 +18,7 @@ new MultipartValue('sidekick', 'Mantas'), ]); - expect($body->get())->toEqual([ + expect($body->all())->toEqual([ 'name' => new MultipartValue('name', 'Sam'), 'sidekick' => new MultipartValue('sidekick', 'Mantas'), ]); @@ -49,7 +49,7 @@ new MultipartValue('username', 'Sammyjo20'), ]); - expect($body->get())->toEqual([ + expect($body->all())->toEqual([ 'username' => new MultipartValue('username', 'Sammyjo20'), ]); }); @@ -59,7 +59,7 @@ $body->add('name', 'Sam', 'welcome.txt', ['a' => 'b']); - expect($body->get())->toEqual([ + expect($body->all())->toEqual([ 'name' => new MultipartValue('name', 'Sam', 'welcome.txt', ['a' => 'b']), ]); @@ -67,7 +67,7 @@ $body->add('name', 'Charlotte', 'welcome.txt', ['a' => 'b']); - expect($body->get())->toEqual([ + expect($body->all())->toEqual([ 'name' => new MultipartValue('name', 'Charlotte', 'welcome.txt', ['a' => 'b']), ]); }); @@ -80,7 +80,7 @@ $body->when(true, fn (MultipartBodyRepository $body) => $body->add('sidekick', 'Mantas')); $body->when(false, fn (MultipartBodyRepository $body) => $body->add('sidekick', 'Teo')); - expect($body->get())->toEqual([ + expect($body->all())->toEqual([ 'name' => new MultipartValue('name', 'Gareth'), 'sidekick' => new MultipartValue('sidekick', 'Mantas'), ]); @@ -92,7 +92,7 @@ $body->add('name', 'Sam'); $body->remove('name'); - expect($body->get())->toEqual([]); + expect($body->all())->toEqual([]); }); test('you can get an item', function () { @@ -115,7 +115,7 @@ ]; expect($body->all())->toEqual($allResults); - expect($body->get())->toEqual($allResults); + expect($body->all())->toEqual($allResults); }); test('you can merge items together into the body repository', function () { @@ -128,7 +128,7 @@ $body->merge([new MultipartValue('sidekick', 'Gareth')], [new MultipartValue('superhero', 'Black Widow')]); - expect($body->get())->toEqual([ + expect($body->all())->toEqual([ 'name' => new MultipartValue('name', 'Sam'), 'sidekick' => new MultipartValue('sidekick', 'Gareth'), 'superhero' => new MultipartValue('superhero', 'Black Widow'), diff --git a/tests/Unit/Body/StreamBodyRepositoryTest.php b/tests/Unit/Body/StreamBodyRepositoryTest.php index 2777423d..0e97d4ff 100644 --- a/tests/Unit/Body/StreamBodyRepositoryTest.php +++ b/tests/Unit/Body/StreamBodyRepositoryTest.php @@ -8,6 +8,7 @@ test('the store is empty by default', function () { $body = new StreamBodyRepository(); + expect($body->all())->toBeNull(); expect($body->get())->toBeNull(); }); @@ -17,6 +18,7 @@ $body = new StreamBodyRepository($resource); + expect($body->all())->toEqual($resource); expect($body->get())->toEqual($resource); }); diff --git a/tests/Unit/Body/StringBodyRepositoryTest.php b/tests/Unit/Body/StringBodyRepositoryTest.php index 69f7b6d9..76015de7 100644 --- a/tests/Unit/Body/StringBodyRepositoryTest.php +++ b/tests/Unit/Body/StringBodyRepositoryTest.php @@ -7,14 +7,14 @@ test('the store is empty by default', function () { $body = new StringBodyRepository(); - expect($body->get())->toBeNull(); + expect($body->all())->toBeNull(); }); test('the store can have a default string provided', function () { $body = new StringBodyRepository('Yeehaw!'); - expect($body->get())->toEqual('Yeehaw!'); + expect($body->all())->toEqual('Yeehaw!'); }); test('you can set it', function () { @@ -22,7 +22,7 @@ $body->set('Yeehaw!'); - expect($body->get())->toEqual('Yeehaw!'); + expect($body->all())->toEqual('Yeehaw!'); }); test('you can conditionally set on the store', function () { @@ -31,7 +31,7 @@ $body->when(true, fn (StringBodyRepository $body) => $body->set('Gareth')); $body->when(false, fn (StringBodyRepository $body) => $body->set('Sam')); - expect($body->get())->toEqual('Gareth'); + expect($body->all())->toEqual('Gareth'); }); test('you can check if the store is empty or not', function () { diff --git a/tests/Unit/MockResponseTest.php b/tests/Unit/MockResponseTest.php index 8c8184b0..fc54b922 100644 --- a/tests/Unit/MockResponseTest.php +++ b/tests/Unit/MockResponseTest.php @@ -28,7 +28,7 @@ expect($response->headers()->all())->toEqual(['Content-Type' => 'application/json']); expect($response->status())->toEqual(200); expect($response->body())->toBeInstanceOf(StringBodyRepository::class); - expect($response->body()->get())->toEqual('xml'); + expect($response->body()->all())->toEqual('xml'); }); test('a response can be a custom response class', function () {