Skip to content

Commit

Permalink
[11.x] Allow passing bool to facade Http@preventStrayRequests() (#53992)
Browse files Browse the repository at this point in the history
* Allow passing bool to Http@preventStrayRequests()

* adds test
  • Loading branch information
cosmastech authored Dec 20, 2024
1 parent 5d81b45 commit fd225c8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Illuminate/Support/Facades/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
}

Expand Down
11 changes: 11 additions & 0 deletions tests/Support/SupportFacadesHttpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit fd225c8

Please sign in to comment.