From 480b6621519439c31b759a3dac8f5ad48e37bf37 Mon Sep 17 00:00:00 2001 From: Milwad Date: Fri, 9 Aug 2024 00:20:31 +0330 Subject: [PATCH 1/4] add `testFromRemoveHeader` --- .../Testing/Concerns/MakesHttpRequestsTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/Foundation/Testing/Concerns/MakesHttpRequestsTest.php b/tests/Foundation/Testing/Concerns/MakesHttpRequestsTest.php index e848cf378a61..7ee4217d9ae7 100644 --- a/tests/Foundation/Testing/Concerns/MakesHttpRequestsTest.php +++ b/tests/Foundation/Testing/Concerns/MakesHttpRequestsTest.php @@ -30,6 +30,17 @@ 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 testWithTokenSetsAuthorizationHeader() { $this->withToken('foobar'); From db87d64fc325dedc505132e23a34e72632b31854 Mon Sep 17 00:00:00 2001 From: Milwad Date: Fri, 9 Aug 2024 00:22:32 +0330 Subject: [PATCH 2/4] add `withoutHeaders` --- .../Testing/Concerns/MakesHttpRequests.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php b/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php index 85eabee130b6..c24799df0b45 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. * From faa556832591a1cbf656115d92fe97bd8e2deed1 Mon Sep 17 00:00:00 2001 From: Milwad Date: Fri, 9 Aug 2024 00:22:42 +0330 Subject: [PATCH 3/4] add `testFromRemoveHeaders` --- .../Testing/Concerns/MakesHttpRequestsTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/Foundation/Testing/Concerns/MakesHttpRequestsTest.php b/tests/Foundation/Testing/Concerns/MakesHttpRequestsTest.php index 7ee4217d9ae7..6c2d8bbc8fa7 100644 --- a/tests/Foundation/Testing/Concerns/MakesHttpRequestsTest.php +++ b/tests/Foundation/Testing/Concerns/MakesHttpRequestsTest.php @@ -41,6 +41,22 @@ public function testFromRemoveHeader() $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'); From 70663cba920c7420db8b6ab314d40a126b3dbfc5 Mon Sep 17 00:00:00 2001 From: Milwad Date: Fri, 9 Aug 2024 00:26:26 +0330 Subject: [PATCH 4/4] Update MakesHttpRequestsTest.php --- tests/Foundation/Testing/Concerns/MakesHttpRequestsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Foundation/Testing/Concerns/MakesHttpRequestsTest.php b/tests/Foundation/Testing/Concerns/MakesHttpRequestsTest.php index 6c2d8bbc8fa7..3a5332fdf20e 100644 --- a/tests/Foundation/Testing/Concerns/MakesHttpRequestsTest.php +++ b/tests/Foundation/Testing/Concerns/MakesHttpRequestsTest.php @@ -45,7 +45,7 @@ public function testFromRemoveHeaders() { $this->withHeaders([ 'name' => 'Milwad', - 'foo' => 'bar' + 'foo' => 'bar', ])->from('previous/url'); $this->assertEquals('Milwad', $this->defaultHeaders['name']);