-
Notifications
You must be signed in to change notification settings - Fork 86
Fixes #36 Client::setUri() should keep relative uri status #149
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it was like that before, but we can do two changes here:
- remove redundant bracket
- change
==
to===
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done ;)
test/ClientTest.php
Outdated
{ | ||
$client = new Client('/example'); | ||
$client->setAdapter(Test::class); | ||
$client->send(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no any assertion in that test. It is really unclear what we are testing here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done ;)
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What behavior is this testing, exactly? This should likely be "testUriCorrectlyDeterminesWhetherOrNotItIsAValidRelativeUri".
test/ClientTest.php
Outdated
return [ | ||
['/example', true], | ||
['http://localhost/example', false] | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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],
test/ClientTest.php
Outdated
return [ | ||
['https://localhost/example', 443], | ||
['http://localhost/example', 80] | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚢
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
master
branch, and submit against that branch.CHANGELOG.md
entry for the fix.