Skip to content

Commit

Permalink
[11.x] Add withoutHeaders method (#52435)
Browse files Browse the repository at this point in the history
* add `testFromRemoveHeader`

* add `withoutHeaders`

* add `testFromRemoveHeaders`

* Update MakesHttpRequestsTest.php
  • Loading branch information
milwad-dev authored Aug 9, 2024
1 parent 0e39947 commit 6ce800f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,21 @@ public function withoutHeader(string $name)
return $this;
}

/**
* Remove headers from the request.
*
* @param array $headers
* @return $this
*/
public function withoutHeaders(array $headers)
{
foreach ($headers as $name) {
$this->withoutHeader($name);
}

return $this;
}

/**
* Add an authorization token for the request.
*
Expand Down
27 changes: 27 additions & 0 deletions tests/Foundation/Testing/Concerns/MakesHttpRequestsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,33 @@ public function testFromRouteSetsHeaderAndSession()
$this->assertSame('http://localhost/previous/url', $this->app['session']->previousUrl());
}

public function testFromRemoveHeader()
{
$this->withHeader('name', 'Milwad')->from('previous/url');

$this->assertEquals('Milwad', $this->defaultHeaders['name']);

$this->withoutHeader('name')->from('previous/url');

$this->assertArrayNotHasKey('name', $this->defaultHeaders);
}

public function testFromRemoveHeaders()
{
$this->withHeaders([
'name' => 'Milwad',
'foo' => 'bar',
])->from('previous/url');

$this->assertEquals('Milwad', $this->defaultHeaders['name']);
$this->assertEquals('bar', $this->defaultHeaders['foo']);

$this->withoutHeaders(['name', 'foo'])->from('previous/url');

$this->assertArrayNotHasKey('name', $this->defaultHeaders);
$this->assertArrayNotHasKey('foo', $this->defaultHeaders);
}

public function testWithTokenSetsAuthorizationHeader()
{
$this->withToken('foobar');
Expand Down

0 comments on commit 6ce800f

Please sign in to comment.