Fixes #36 Client::setUri() should keep relative uri status#149
Fixes #36 Client::setUri() should keep relative uri status#149weierophinney merged 21 commits intozendframework:masterfrom
Conversation
|
After some check, I think relative url should not be allowed instead in
thought ? |
src/Client.php
Outdated
| // 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()) { |
There was a problem hiding this comment.
We need brackets around expressions here, see following example - https://3v4l.org/oV5F5:
<?php
function a() {
return 1;
}
function b() {
return 2;
}
if ($a = a() && $b = b()) {
var_dump($a, $b);
}results:
bool(true)
int(2)
and because of that I think there is missing proper test for that change.
There was a problem hiding this comment.
I see bracket added, but still I can't see any test for it :)
src/Client.php
Outdated
| if (! $this->getUri()->getPort()) { | ||
| $this->getUri()->setPort(($this->getUri()->getScheme() == 'https' ? 443 : 80)); | ||
| if (! $uri->getPort() && $uri->isAbsolute()) { | ||
| $uri->setPort(($uri->getScheme() == 'https' ? 443 : 80)); |
There was a problem hiding this comment.
I know it was like that before, but we can do two changes here:
- remove redundant bracket
- change
==to===
| { | ||
| $client = new Client('/example'); | ||
| $client->setAdapter(Test::class); | ||
| $client->send(); |
There was a problem hiding this comment.
There is no any assertion in that test. It is really unclear what we are testing here.
|
@webimpress I've added the tests for check |
src/Client.php
Outdated
| // 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())) { |
There was a problem hiding this comment.
Please don't do assignments in conditionals.
test/ClientTest.php
Outdated
| /** | ||
| * @dataProvider uriDataProvider | ||
| */ | ||
| public function testValidRelativeURI($uri, $isValidRelativeURI) |
There was a problem hiding this comment.
What behavior is this testing, exactly? This should likely be "testUriCorrectlyDeterminesWhetherOrNotItIsAValidRelativeUri".
| return [ | ||
| ['/example', true], | ||
| ['http://localhost/example', false] | ||
| ]; |
There was a problem hiding this comment.
Please add names for each case in the provider. This makes it simpler to determine which case failed when a failure occurs. As an example:
'valid-relative' => ['/example', true],
'invalid-absolute' => ['http://localhost/example', false],| return [ | ||
| ['https://localhost/example', 443], | ||
| ['http://localhost/example', 80] | ||
| ]; |
There was a problem hiding this comment.
Same comment here about adding names for each provider case.
test/ClientTest.php
Outdated
| /** | ||
| * @dataProvider portChangeDataProvider | ||
| */ | ||
| public function testAbsoluteSetPortWhenNoPort($absoluteURI, $port) |
There was a problem hiding this comment.
This needs a name that better describes the behavior being tested: "testUriPortIsSetToAppropriateDefaultValueWhenAnAbsoluteUriOmittingThePortIsProvided".
test/ClientTest.php
Outdated
| $this->assertSame($port, $client->getUri()->getPort()); | ||
| } | ||
|
|
||
| public function testRelativeURIDoesnotSetPort() |
There was a problem hiding this comment.
Need a better method name here; I'll leave this as an exercise for you!
|
@weierophinney done ;). All incorporated. |
|
@weierophinney should be fixed now |
|
travis green |
|
@weierophinney mergeable ? |
Fixes #36 Client::setUri() should keep relative uri status Conflicts: CHANGELOG.md
|
Thanks, @samsonasik ! |
|
@weierophinney @samsonasik can you help me to understand this PR? I was working to another branch adding checks to ensure uri host exists. |
|
it make keep relative uri status, for host exists check, I already commented before at #149 (comment) but that will not related to this PR, keeping exisitng URI host for relative uri seems need another PR |
Provide a narrative description of what you are trying to accomplish:
Supply relative uri to
Client::setUri()It convert to absolute uri
It should keep as relative uri
masterbranch, and submit against that branch.CHANGELOG.mdentry for the fix.