Skip to content

Commit fd225c8

Browse files
authored
[11.x] Allow passing bool to facade Http@preventStrayRequests() (#53992)
* Allow passing bool to Http@preventStrayRequests() * adds test
1 parent 5d81b45 commit fd225c8

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/Illuminate/Support/Facades/Http.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,13 @@ public static function fakeSequence(string $urlPattern = '*')
138138
/**
139139
* Indicate that an exception should be thrown if any request is not faked.
140140
*
141+
* @param bool $prevent
141142
* @return \Illuminate\Http\Client\Factory
142143
*/
143-
public static function preventStrayRequests()
144+
public static function preventStrayRequests($prevent = true)
144145
{
145-
return tap(static::getFacadeRoot(), function ($fake) {
146-
static::swap($fake->preventStrayRequests());
146+
return tap(static::getFacadeRoot(), function ($fake) use ($prevent) {
147+
static::swap($fake->preventStrayRequests($prevent));
147148
});
148149
}
149150

tests/Support/SupportFacadesHttpTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,15 @@ public function testFacadeRootIsSharedWhenEnforcingFaking(): void
5555

5656
$this->assertSame($client, $this->app->make(Factory::class));
5757
}
58+
59+
public function test_can_set_prevents_to_prevents_stray_requests(): void
60+
{
61+
Http::preventStrayRequests(true);
62+
$this->assertTrue($this->app->make(Factory::class)->preventingStrayRequests());
63+
$this->assertTrue(Http::preventingStrayRequests());
64+
65+
Http::preventStrayRequests(false);
66+
$this->assertFalse($this->app->make(Factory::class)->preventingStrayRequests());
67+
$this->assertFalse(Http::preventingStrayRequests());
68+
}
5869
}

0 commit comments

Comments
 (0)