From 3a8fa0b506787129ee1b9d52cf1bc8c2b0eb0aa7 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sun, 6 May 2018 10:24:23 +0700 Subject: [PATCH 01/21] Fixes #36 Client::setUri() should keep relative uri status --- src/Client.php | 2 +- test/ClientTest.php | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index dab67b8f7..c2e8c432c 100644 --- a/src/Client.php +++ b/src/Client.php @@ -330,7 +330,7 @@ public function setUri($uri) } // We have no ports, set the defaults - if (! $this->getUri()->getPort()) { + if (! $this->getUri()->getPort() && $this->getUri()->isAbsolute()) { $this->getUri()->setPort(($this->getUri()->getScheme() == 'https' ? 443 : 80)); } } diff --git a/test/ClientTest.php b/test/ClientTest.php index 0794927f2..03d453e12 100644 --- a/test/ClientTest.php +++ b/test/ClientTest.php @@ -524,4 +524,21 @@ public function testFormUrlEncodeSeparator() $rawRequest = $client->getLastRawRequest(); $this->assertContains('foo=bar&baz=foo', $rawRequest); } + + public function uriDataProvider() + { + return [ + ['example', true], + ['http://localhost/example', false] + ]; + } + + /** + * @dataProvider uriDataProvider + */ + public function testValidRelativeURI($uri, $isValidRelativeURI) + { + $client = new Client($uri); + $this->assertSame($isValidRelativeURI, $client->getUri()->isValidRelative()); + } } From fa28d863d917fc0d2f3d7e408a56660949e79362 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sun, 6 May 2018 10:27:42 +0700 Subject: [PATCH 02/21] #149 changelog entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b97e65b8a..e646640e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -106,7 +106,7 @@ All notable changes to this project will be documented in this file, in reverse ### Fixed -- Nothing. +- [#149](https://github.com/zendframework/zend-http/pull/149) Client::setUri() should keep relative uri status ## 2.8.0 - 2018-04-26 From 7f712227954c0323783fca8cc866a2c026ad4b4a Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sun, 6 May 2018 10:32:50 +0700 Subject: [PATCH 03/21] move repetitive getUri() call to variable uri --- src/Client.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Client.php b/src/Client.php index c2e8c432c..aacdcb715 100644 --- a/src/Client.php +++ b/src/Client.php @@ -324,14 +324,16 @@ public function setUri($uri) $this->clearAuth(); } + $uri = $this->getUri(); + // Set auth if username and password has been specified in the uri - if ($this->getUri()->getUser() && $this->getUri()->getPassword()) { - $this->setAuth($this->getUri()->getUser(), $this->getUri()->getPassword()); + if ($user = $uri->getUser() && $password = $uri->getPassword()) { + $this->setAuth($user, $password); } // We have no ports, set the defaults - if (! $this->getUri()->getPort() && $this->getUri()->isAbsolute()) { - $this->getUri()->setPort(($this->getUri()->getScheme() == 'https' ? 443 : 80)); + if (! $uri->getPort() && $uri->isAbsolute()) { + $uri->setPort(($uri->getScheme() == 'https' ? 443 : 80)); } } return $this; From cd7c029e68a2a5732417305307fbc726315ef53c Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sun, 6 May 2018 10:39:27 +0700 Subject: [PATCH 04/21] relative uri / prefix --- test/ClientTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/ClientTest.php b/test/ClientTest.php index 03d453e12..89beee3cf 100644 --- a/test/ClientTest.php +++ b/test/ClientTest.php @@ -528,7 +528,7 @@ public function testFormUrlEncodeSeparator() public function uriDataProvider() { return [ - ['example', true], + ['/example', true], ['http://localhost/example', false] ]; } From 145acdb7edaeb4d0a2a52ac94c1fe5d6e6201cf2 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sun, 6 May 2018 11:02:20 +0700 Subject: [PATCH 05/21] test Client::send() with relative uri --- src/Client.php | 2 +- test/ClientTest.php | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index aacdcb715..b30cfcee4 100644 --- a/src/Client.php +++ b/src/Client.php @@ -903,7 +903,7 @@ public function send(Request $request = null) } } // If we have no ports, set the defaults - if (! $uri->getPort()) { + if (! $uri->getPort() && $uri->isAbsolute()) { $uri->setPort($uri->getScheme() == 'https' ? 443 : 80); } diff --git a/test/ClientTest.php b/test/ClientTest.php index 89beee3cf..2f1cdf3df 100644 --- a/test/ClientTest.php +++ b/test/ClientTest.php @@ -541,4 +541,11 @@ public function testValidRelativeURI($uri, $isValidRelativeURI) $client = new Client($uri); $this->assertSame($isValidRelativeURI, $client->getUri()->isValidRelative()); } + + public function testSendRequestWithRelativeURI() + { + $client = new Client('/example'); + $client->setAdapter(Test::class); + $client->send(); + } } From f6707c03388c8fa3c4ded412c5ba64faffccad8d Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 7 May 2018 09:10:47 +0700 Subject: [PATCH 06/21] bracket and === fix --- src/Client.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Client.php b/src/Client.php index b30cfcee4..9cf64617f 100644 --- a/src/Client.php +++ b/src/Client.php @@ -327,13 +327,13 @@ public function setUri($uri) $uri = $this->getUri(); // Set auth if username and password has been specified in the uri - if ($user = $uri->getUser() && $password = $uri->getPassword()) { + if (($user = $uri->getUser()) && ($password = $uri->getPassword())) { $this->setAuth($user, $password); } // We have no ports, set the defaults if (! $uri->getPort() && $uri->isAbsolute()) { - $uri->setPort(($uri->getScheme() == 'https' ? 443 : 80)); + $uri->setPort($uri->getScheme() === 'https' ? 443 : 80); } } return $this; @@ -904,7 +904,7 @@ public function send(Request $request = null) } // If we have no ports, set the defaults if (! $uri->getPort() && $uri->isAbsolute()) { - $uri->setPort($uri->getScheme() == 'https' ? 443 : 80); + $uri->setPort($uri->getScheme() === 'https' ? 443 : 80); } // method From 39ca2b4ad7775f4917fe350e646a5c5adbfcf2e1 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 7 May 2018 09:12:12 +0700 Subject: [PATCH 07/21] add assertion for testSendRequestWithRelativeURI() --- test/ClientTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/test/ClientTest.php b/test/ClientTest.php index 2f1cdf3df..7ef1f6b61 100644 --- a/test/ClientTest.php +++ b/test/ClientTest.php @@ -547,5 +547,6 @@ public function testSendRequestWithRelativeURI() $client = new Client('/example'); $client->setAdapter(Test::class); $client->send(); + $this->assertTrue($client->getUri()->isValidRelative()); } } From 5198676dc0fa0dcb8e18a17c3a58d4ac582dd380 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 7 May 2018 11:42:01 +0700 Subject: [PATCH 08/21] test isValidRelative() === false on absolute uri client send --- test/ClientTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/ClientTest.php b/test/ClientTest.php index 7ef1f6b61..188cd5423 100644 --- a/test/ClientTest.php +++ b/test/ClientTest.php @@ -549,4 +549,12 @@ public function testSendRequestWithRelativeURI() $client->send(); $this->assertTrue($client->getUri()->isValidRelative()); } + + public function testSendRequestWithAbsoluteURI() + { + $client = new Client('http://localhost/example'); + $client->setAdapter(Test::class); + $client->send(); + $this->assertFalse($client->getUri()->isValidRelative()); + } } From 14f74f140fdea9508dcec5d63e7808c6951c09c9 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 7 May 2018 15:53:41 +0700 Subject: [PATCH 09/21] add test for isAbsolute() check set port --- test/ClientTest.php | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/test/ClientTest.php b/test/ClientTest.php index 188cd5423..ec73c0b1a 100644 --- a/test/ClientTest.php +++ b/test/ClientTest.php @@ -540,21 +540,40 @@ public function testValidRelativeURI($uri, $isValidRelativeURI) { $client = new Client($uri); $this->assertSame($isValidRelativeURI, $client->getUri()->isValidRelative()); + + $client->setAdapter(Test::class); + $client->send(); + $this->assertSame($isValidRelativeURI, $client->getUri()->isValidRelative()); } - public function testSendRequestWithRelativeURI() + public function portChangeDataProvider() { - $client = new Client('/example'); + return [ + ['https://localhost/example', 443], + ['http://localhost/example', 80] + ]; + } + + /** + * @dataProvider portChangeDataProvider + */ + public function testAbsoluteSetPort443OnHttps($absoluteURI, $port) + { + $client = new Client($absoluteURI); + $this->assertSame($port, $client->getUri()->getPort()); + $client->setAdapter(Test::class); $client->send(); - $this->assertTrue($client->getUri()->isValidRelative()); + $this->assertSame($port, $client->getUri()->getPort()); } - public function testSendRequestWithAbsoluteURI() + public function testRelativeURIDoesnotSetPort() { - $client = new Client('http://localhost/example'); + $client = new Client('/example'); + $this->assertSame(null, $client->getUri()->getPort()); + $client->setAdapter(Test::class); $client->send(); - $this->assertFalse($client->getUri()->isValidRelative()); + $this->assertSame(null, $client->getUri()->getPort()); } } From 89ea24e950baedc93db3a2cf975be8132ad9af99 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 7 May 2018 15:54:26 +0700 Subject: [PATCH 10/21] assertNull() --- test/ClientTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/ClientTest.php b/test/ClientTest.php index ec73c0b1a..9d21d1504 100644 --- a/test/ClientTest.php +++ b/test/ClientTest.php @@ -570,10 +570,10 @@ public function testAbsoluteSetPort443OnHttps($absoluteURI, $port) public function testRelativeURIDoesnotSetPort() { $client = new Client('/example'); - $this->assertSame(null, $client->getUri()->getPort()); + $this->assertNull($client->getUri()->getPort()); $client->setAdapter(Test::class); $client->send(); - $this->assertSame(null, $client->getUri()->getPort()); + $this->assertNull($client->getUri()->getPort()); } } From e36229826226fb4637cc08ec1d66a11d6ec975ce Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 7 May 2018 16:13:11 +0700 Subject: [PATCH 11/21] no port test --- test/ClientTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/ClientTest.php b/test/ClientTest.php index 9d21d1504..2152fbcc1 100644 --- a/test/ClientTest.php +++ b/test/ClientTest.php @@ -557,9 +557,10 @@ public function portChangeDataProvider() /** * @dataProvider portChangeDataProvider */ - public function testAbsoluteSetPort443OnHttps($absoluteURI, $port) + public function testAbsoluteSetPortWhenNoPort($absoluteURI, $port) { $client = new Client($absoluteURI); + $client->setPort(null); $this->assertSame($port, $client->getUri()->getPort()); $client->setAdapter(Test::class); From 5e96389b9249ac4e741b0084c9c07b616d810c9a Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 7 May 2018 16:14:49 +0700 Subject: [PATCH 12/21] no port test --- test/ClientTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/ClientTest.php b/test/ClientTest.php index 2152fbcc1..600e5ff79 100644 --- a/test/ClientTest.php +++ b/test/ClientTest.php @@ -560,7 +560,7 @@ public function portChangeDataProvider() public function testAbsoluteSetPortWhenNoPort($absoluteURI, $port) { $client = new Client($absoluteURI); - $client->setPort(null); + $client->getUri()->setPort(null); $this->assertSame($port, $client->getUri()->getPort()); $client->setAdapter(Test::class); From 3132fe9a2df523e31f64434c564bd70c0f769c12 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 7 May 2018 16:15:29 +0700 Subject: [PATCH 13/21] no port test --- test/ClientTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/ClientTest.php b/test/ClientTest.php index 600e5ff79..cb6d6921b 100644 --- a/test/ClientTest.php +++ b/test/ClientTest.php @@ -559,8 +559,10 @@ public function portChangeDataProvider() */ public function testAbsoluteSetPortWhenNoPort($absoluteURI, $port) { - $client = new Client($absoluteURI); + $client = new Client(); $client->getUri()->setPort(null); + + $client->setUri($absoluteURI); $this->assertSame($port, $client->getUri()->getPort()); $client->setAdapter(Test::class); From 427e54e5fc79734af96143f549bad0fc703ff5ed Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 14 Aug 2018 02:12:22 +0700 Subject: [PATCH 14/21] move changelog to 2.8.3 --- CHANGELOG.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e646640e3..2f36c9fd0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,7 @@ All notable changes to this project will be documented in this file, in reverse ### Fixed -- Nothing. +[#149](https://github.com/zendframework/zend-http/pull/149) Client::setUri() should keep relative uri status ## 2.8.2 - 2018-08-13 @@ -106,7 +106,7 @@ All notable changes to this project will be documented in this file, in reverse ### Fixed -- [#149](https://github.com/zendframework/zend-http/pull/149) Client::setUri() should keep relative uri status +- Nothing. ## 2.8.0 - 2018-04-26 @@ -336,4 +336,4 @@ All notable changes to this project will be documented in this file, in reverse - [#14](https://github.com/zendframework/zend-http/pull/14) fixes `Zend\Http\PhpEnvironment\Request` to ensure that empty `SCRIPT_FILENAME` and `SCRIPT_NAME` values which result in an empty `$baseUrl` will not raise an - `E_WARNING` when used to do a `strpos()` check during base URI detection. + `E_WARNING` when used to do a `strpos()` check during base URI detection. \ No newline at end of file From 951098fb644ef4f8eeefcb0e78e85244f72ff210 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 14 Aug 2018 02:14:22 +0700 Subject: [PATCH 15/21] move assignment outside if --- src/Client.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 9cf64617f..9396f591b 100644 --- a/src/Client.php +++ b/src/Client.php @@ -325,9 +325,11 @@ public function setUri($uri) } $uri = $this->getUri(); + $user = $uri->getUser(); + $password = $uri->getPassword(); // Set auth if username and password has been specified in the uri - if (($user = $uri->getUser()) && ($password = $uri->getPassword())) { + if ($user && $password) { $this->setAuth($user, $password); } From 74325d63e161b9fd433a3c536ecd4d7888551fc2 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 14 Aug 2018 02:16:18 +0700 Subject: [PATCH 16/21] add name on each provider for uriDataProvider --- test/ClientTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/ClientTest.php b/test/ClientTest.php index cb6d6921b..cbbe13c83 100644 --- a/test/ClientTest.php +++ b/test/ClientTest.php @@ -528,8 +528,8 @@ public function testFormUrlEncodeSeparator() public function uriDataProvider() { return [ - ['/example', true], - ['http://localhost/example', false] + ['valid-relative' => ['/example', true]], + ['invalid-absolute' => ['http://localhost/example', false]] ]; } From 92f8cf3ea4f7a878a01a2ee2f507844028fd4c98 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 14 Aug 2018 02:18:31 +0700 Subject: [PATCH 17/21] name test for correctly determine valid uri for relative and absolute --- test/ClientTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/ClientTest.php b/test/ClientTest.php index cbbe13c83..66c0e2cdb 100644 --- a/test/ClientTest.php +++ b/test/ClientTest.php @@ -536,7 +536,7 @@ public function uriDataProvider() /** * @dataProvider uriDataProvider */ - public function testValidRelativeURI($uri, $isValidRelativeURI) + public function testUriCorrectlyDeterminesWhetherOrNotItIsAValidRelativeUri($uri, $isValidRelativeURI) { $client = new Client($uri); $this->assertSame($isValidRelativeURI, $client->getUri()->isValidRelative()); From 2b5e5887ab3e5e77f992d7b2fdd20d5c7ca46b79 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 14 Aug 2018 02:25:21 +0700 Subject: [PATCH 18/21] dataProvider naming in each row fix --- test/ClientTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/ClientTest.php b/test/ClientTest.php index 66c0e2cdb..d6e5f8504 100644 --- a/test/ClientTest.php +++ b/test/ClientTest.php @@ -528,8 +528,8 @@ public function testFormUrlEncodeSeparator() public function uriDataProvider() { return [ - ['valid-relative' => ['/example', true]], - ['invalid-absolute' => ['http://localhost/example', false]] + 'valid-relative' => ['/example', true], + 'invalid-absolute' => ['http://localhost/example', false], ]; } @@ -549,8 +549,8 @@ public function testUriCorrectlyDeterminesWhetherOrNotItIsAValidRelativeUri($uri public function portChangeDataProvider() { return [ - ['https://localhost/example', 443], - ['http://localhost/example', 80] + 'default-https' => ['https://localhost/example', 443], + 'default-http' => ['http://localhost/example', 80] ]; } From 47dbd2e0fd36eb9d5c353be6e85dba1d6759bd66 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 14 Aug 2018 02:25:55 +0700 Subject: [PATCH 19/21] test name for approprite port on set absolute uri --- test/ClientTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/ClientTest.php b/test/ClientTest.php index d6e5f8504..b4fd07fff 100644 --- a/test/ClientTest.php +++ b/test/ClientTest.php @@ -557,7 +557,7 @@ public function portChangeDataProvider() /** * @dataProvider portChangeDataProvider */ - public function testAbsoluteSetPortWhenNoPort($absoluteURI, $port) + public function testUriPortIsSetToAppropriateDefaultValueWhenAnAbsoluteUriOmittingThePortIsProvided($absoluteURI, $port) { $client = new Client(); $client->getUri()->setPort(null); From b8f12e0665dbb32c833c2a14310befc2443ba568 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 14 Aug 2018 02:27:39 +0700 Subject: [PATCH 20/21] test name for port not set on relative uri --- test/ClientTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/ClientTest.php b/test/ClientTest.php index b4fd07fff..f32095485 100644 --- a/test/ClientTest.php +++ b/test/ClientTest.php @@ -570,7 +570,7 @@ public function testUriPortIsSetToAppropriateDefaultValueWhenAnAbsoluteUriOmitti $this->assertSame($port, $client->getUri()->getPort()); } - public function testRelativeURIDoesnotSetPort() + public function testUriPortIsNotSetWhenUriIsRelative() { $client = new Client('/example'); $this->assertNull($client->getUri()->getPort()); From aa482989bf972bb625ba6e6f23fd71d71b8accfb Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 14 Aug 2018 02:53:45 +0700 Subject: [PATCH 21/21] cs fix --- test/ClientTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/ClientTest.php b/test/ClientTest.php index f32095485..2b018d0e7 100644 --- a/test/ClientTest.php +++ b/test/ClientTest.php @@ -557,7 +557,7 @@ public function portChangeDataProvider() /** * @dataProvider portChangeDataProvider */ - public function testUriPortIsSetToAppropriateDefaultValueWhenAnAbsoluteUriOmittingThePortIsProvided($absoluteURI, $port) + public function testUriPortIsSetToAppropriateDefaultValueWhenAnUriOmittingThePortIsProvided($absoluteURI, $port) { $client = new Client(); $client->getUri()->setPort(null);