|
168 | 168 |
|
169 | 169 | expect($mockClient)->getLastRequest()->toBeNull(); |
170 | 170 | }); |
| 171 | + |
| 172 | +test('if the response is not the last response it will use the loop to find it', function () { |
| 173 | + $mockClient = new MockClient([ |
| 174 | + new MockResponse(['name' => 'Sam'], 200), |
| 175 | + new MockResponse(['error' => 'Server Error'], 500), |
| 176 | + ]); |
| 177 | + |
| 178 | + $responseA = (new ErrorRequest())->send($mockClient); |
| 179 | + $responseB = (new UserRequest())->send($mockClient); |
| 180 | + |
| 181 | + expect($mockClient)->getLastResponse()->toBe($responseB); |
| 182 | + |
| 183 | + // Uses last response |
| 184 | + |
| 185 | + expect($mockClient)->findResponseByRequest(UserRequest::class)->toBe($responseB); |
| 186 | + |
| 187 | + // Does not use the last response |
| 188 | + |
| 189 | + expect($mockClient)->findResponseByRequest(ErrorRequest::class)->toBe($responseA); |
| 190 | +}); |
| 191 | + |
| 192 | +test('it will find the response by url if it is not the last response', function () { |
| 193 | + $mockClient = new MockClient([ |
| 194 | + '/user' => new MockResponse(['name' => 'Sam'], 200), |
| 195 | + '/error' => new MockResponse(['error' => 'Server Error'], 500), |
| 196 | + ]); |
| 197 | + |
| 198 | + $responseA = (new ErrorRequest())->send($mockClient); |
| 199 | + $responseB = (new UserRequest())->send($mockClient); |
| 200 | + |
| 201 | + expect($mockClient)->getLastResponse()->toBe($responseB); |
| 202 | + |
| 203 | + // Uses last response |
| 204 | + |
| 205 | + expect($mockClient)->findResponseByRequestUrl('/user')->toBe($responseB); |
| 206 | + |
| 207 | + // Does not use the last response |
| 208 | + |
| 209 | + expect($mockClient)->findResponseByRequestUrl('/error')->toBe($responseA); |
| 210 | +}); |
0 commit comments