diff --git a/src/Illuminate/Support/Facades/Http.php b/src/Illuminate/Support/Facades/Http.php index 83217a04b22..60489694d3c 100644 --- a/src/Illuminate/Support/Facades/Http.php +++ b/src/Illuminate/Support/Facades/Http.php @@ -138,12 +138,13 @@ public static function fakeSequence(string $urlPattern = '*') /** * Indicate that an exception should be thrown if any request is not faked. * + * @param bool $prevent * @return \Illuminate\Http\Client\Factory */ - public static function preventStrayRequests() + public static function preventStrayRequests($prevent = true) { - return tap(static::getFacadeRoot(), function ($fake) { - static::swap($fake->preventStrayRequests()); + return tap(static::getFacadeRoot(), function ($fake) use ($prevent) { + static::swap($fake->preventStrayRequests($prevent)); }); } diff --git a/tests/Support/SupportFacadesHttpTest.php b/tests/Support/SupportFacadesHttpTest.php index fe194d0350d..e7de568c490 100644 --- a/tests/Support/SupportFacadesHttpTest.php +++ b/tests/Support/SupportFacadesHttpTest.php @@ -55,4 +55,15 @@ public function testFacadeRootIsSharedWhenEnforcingFaking(): void $this->assertSame($client, $this->app->make(Factory::class)); } + + public function test_can_set_prevents_to_prevents_stray_requests(): void + { + Http::preventStrayRequests(true); + $this->assertTrue($this->app->make(Factory::class)->preventingStrayRequests()); + $this->assertTrue(Http::preventingStrayRequests()); + + Http::preventStrayRequests(false); + $this->assertFalse($this->app->make(Factory::class)->preventingStrayRequests()); + $this->assertFalse(Http::preventingStrayRequests()); + } }