-
-
Notifications
You must be signed in to change notification settings - Fork 120
Expand file tree
/
Copy pathSimulatedResponsePayloadTest.php
More file actions
26 lines (19 loc) · 908 Bytes
/
SimulatedResponsePayloadTest.php
File metadata and controls
26 lines (19 loc) · 908 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php
declare(strict_types=1);
use Saloon\Http\Faking\MockClient;
use Saloon\Http\Faking\FakeResponse;
use Saloon\Http\Faking\MockResponse;
use Saloon\Tests\Fixtures\Requests\UserRequest;
use Saloon\Tests\Fixtures\Connectors\TestConnector;
test('if a simulated response payload was provided before mock response it will take priority', function () {
$mockClient = new MockClient([
new MockResponse(['name' => 'Sam'], 200, ['X-Greeting' => 'Howdy']),
]);
$fakeResponse = new FakeResponse(['name' => 'Gareth'], 201, ['X-Greeting' => 'Hello']);
$request = new UserRequest;
$request->middleware()->onRequest(fn () => $fakeResponse);
$response = TestConnector::make()->send($request, $mockClient);
expect($response->json())->toEqual(['name' => 'Gareth']);
expect($response->status())->toEqual(201);
expect($response->header('X-Greeting'))->toEqual('Hello');
});