|
21 | 21 | use Illuminate\Http\Client\RequestException; |
22 | 22 | use Illuminate\Http\Client\Response; |
23 | 23 | use Illuminate\Http\Client\ResponseSequence; |
| 24 | +use Illuminate\Http\Client\StrayRequestException; |
24 | 25 | use Illuminate\Http\Response as HttpResponse; |
25 | 26 | use Illuminate\Support\Arr; |
26 | 27 | use Illuminate\Support\Carbon; |
@@ -3178,12 +3179,38 @@ public function testItCanEnforceFaking() |
3178 | 3179 | $responses[] = $this->factory->get('https://forge.laravel.com')->body(); |
3179 | 3180 | $this->assertSame(['ok', 'ok'], $responses); |
3180 | 3181 |
|
3181 | | - $this->expectException(RuntimeException::class); |
| 3182 | + $this->expectException(StrayRequestException::class); |
3182 | 3183 | $this->expectExceptionMessage('Attempted request to [https://laravel.com] without a matching fake.'); |
3183 | 3184 |
|
3184 | 3185 | $this->factory->get('https://laravel.com'); |
3185 | 3186 | } |
3186 | 3187 |
|
| 3188 | + public function testItCanEnforceFakingInThePool() |
| 3189 | + { |
| 3190 | + $this->factory->preventStrayRequests(); |
| 3191 | + $this->factory->fake(['https://vapor.laravel.com' => Factory::response('ok', 200)]); |
| 3192 | + $this->factory->fake(['https://forge.laravel.com' => Factory::response('ok', 200)]); |
| 3193 | + |
| 3194 | + $responses = $this->factory->pool(function (Pool $pool) { |
| 3195 | + return [ |
| 3196 | + $pool->get('https://vapor.laravel.com'), |
| 3197 | + $pool->get('https://forge.laravel.com'), |
| 3198 | + ]; |
| 3199 | + }); |
| 3200 | + |
| 3201 | + $this->assertSame(200, $responses[0]->status()); |
| 3202 | + $this->assertSame(200, $responses[1]->status()); |
| 3203 | + |
| 3204 | + $this->expectException(StrayRequestException::class); |
| 3205 | + $this->expectExceptionMessage('Attempted request to [https://laravel.com] without a matching fake.'); |
| 3206 | + |
| 3207 | + $this->factory->pool(function (Pool $pool) { |
| 3208 | + return [ |
| 3209 | + $pool->get('https://laravel.com'), |
| 3210 | + ]; |
| 3211 | + }); |
| 3212 | + } |
| 3213 | + |
3187 | 3214 | public function testPreventingStrayRequests() |
3188 | 3215 | { |
3189 | 3216 | $this->assertFalse($this->factory->preventingStrayRequests()); |
|
0 commit comments