diff --git a/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php b/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php index 85eabee130b..c24799df0b4 100644 --- a/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php +++ b/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php @@ -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. * diff --git a/tests/Foundation/Testing/Concerns/MakesHttpRequestsTest.php b/tests/Foundation/Testing/Concerns/MakesHttpRequestsTest.php index e848cf378a6..3a5332fdf20 100644 --- a/tests/Foundation/Testing/Concerns/MakesHttpRequestsTest.php +++ b/tests/Foundation/Testing/Concerns/MakesHttpRequestsTest.php @@ -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');