|
1 | 1 | <?php |
2 | 2 |
|
| 3 | +use League\Flysystem\Filesystem; |
| 4 | +use League\Flysystem\Local\LocalFilesystemAdapter; |
3 | 5 | use Sammyjo20\Saloon\Http\Fixture; |
4 | 6 | use Sammyjo20\Saloon\Http\MockResponse; |
5 | 7 | use Sammyjo20\Saloon\Clients\MockClient; |
|
12 | 14 | use Sammyjo20\Saloon\Tests\Fixtures\Connectors\QueryParameterConnector; |
13 | 15 | use Sammyjo20\Saloon\Tests\Fixtures\Requests\DifferentServiceUserRequest; |
14 | 16 | use Sammyjo20\Saloon\Tests\Fixtures\Requests\QueryParameterConnectorRequest; |
| 17 | +use function PHPUnit\Framework\assertFileDoesNotExist; |
| 18 | +use function PHPUnit\Framework\assertFileExists; |
| 19 | + |
| 20 | +$filesystem = new Filesystem(new LocalFilesystemAdapter('tests/Fixtures/Saloon')); |
| 21 | + |
| 22 | +beforeEach(function () use ($filesystem) { |
| 23 | + $filesystem->deleteDirectory('/'); |
| 24 | + $filesystem->createDirectory('/'); |
| 25 | +}); |
15 | 26 |
|
16 | 27 | test('a request can be mocked with a sequence', function () { |
17 | 28 | $mockClient = new MockClient([ |
@@ -224,19 +235,24 @@ function (SaloonRequest $request): MockResponse { |
224 | 235 | expect($sequenceResponse->json())->toEqual(['request_class' => UserRequest::class]); |
225 | 236 | }); |
226 | 237 |
|
227 | | -test('you can tell the mock client to record requests and it will store recorded requests as a fixture', function () { |
| 238 | +test('you can use a fixture mock response and it will record the request for future use', function () use ($filesystem) { |
228 | 239 | $mockClient = new MockClient([ |
229 | 240 | UserRequest::class => MockResponse::fixture('user'), |
230 | | - ErrorRequest::class => MockResponse::fixture('error'), |
231 | 241 | ]); |
232 | 242 |
|
233 | | - $response = UserRequest::make()->send($mockClient); |
| 243 | + expect($filesystem->fileExists('user.json'))->toBeFalse(); |
| 244 | + |
| 245 | + $responseA = UserRequest::make()->send($mockClient); |
234 | 246 |
|
235 | | - $errorResponse = ErrorRequest::make()->send($mockClient); |
| 247 | + expect($responseA->isMocked())->toBeFalse(); |
| 248 | + expect($responseA->status())->toEqual(200); |
| 249 | + |
| 250 | + expect($filesystem->fileExists('user.json'))->toBeTrue(); |
236 | 251 |
|
237 | | - dd($errorResponse->status()); |
| 252 | + $responseB = UserRequest::make()->send($mockClient); |
238 | 253 |
|
239 | | - dd($response->json()); |
| 254 | + expect($responseB->isMocked())->toBeTrue(); |
| 255 | + expect($responseB->status())->toEqual(200); |
240 | 256 | }); |
241 | 257 |
|
242 | 258 | // Tests: Make sure the fixture works with all the mocking types including closures |
0 commit comments