diff --git a/src/Uri.php b/src/Uri.php index 2085ab73..825a25ee 100644 --- a/src/Uri.php +++ b/src/Uri.php @@ -628,9 +628,9 @@ private function filterPort($port) } $port = (int) $port; - if (1 > $port || 0xffff < $port) { + if (0 > $port || 0xffff < $port) { throw new \InvalidArgumentException( - sprintf('Invalid port: %d. Must be between 1 and 65535', $port) + sprintf('Invalid port: %d. Must be between 0 and 65535', $port) ); } diff --git a/tests/UriTest.php b/tests/UriTest.php index 8a9141eb..b9fb7e81 100644 --- a/tests/UriTest.php +++ b/tests/UriTest.php @@ -117,7 +117,7 @@ public function getInvalidUris() /** * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid port: 100000. Must be between 1 and 65535 + * @expectedExceptionMessage Invalid port: 100000. Must be between 0 and 65535 */ public function testPortMustBeValid() { @@ -126,11 +126,11 @@ public function testPortMustBeValid() /** * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid port: 0. Must be between 1 and 65535 + * @expectedExceptionMessage Invalid port: -1. Must be between 0 and 65535 */ - public function testWithPortCannotBeZero() + public function testWithPortCannotBeNegative() { - (new Uri())->withPort(0); + (new Uri())->withPort(-1); } /**