diff --git a/src/Uri.php b/src/Uri.php index d589899..6f51d7f 100644 --- a/src/Uri.php +++ b/src/Uri.php @@ -292,7 +292,7 @@ protected function hasStandardPort(): bool /** * Filter Uri port. * - * @param int|null $port The Uri port number. + * @param int|string|null $port The Uri port number. * * @return int|null * @@ -300,7 +300,13 @@ protected function hasStandardPort(): bool */ protected function filterPort($port): ?int { - if (is_null($port) || (is_integer($port) && ($port >= 1 && $port <= 65535))) { + if (is_null($port)) { + return null; + } + + $port = (int) $port; + + if ($port >= 1 && $port <= 65535) { return $port; } diff --git a/tests/UriTest.php b/tests/UriTest.php index a0c4d28..92077ec 100644 --- a/tests/UriTest.php +++ b/tests/UriTest.php @@ -215,6 +215,13 @@ public function testWithPortInvalidString() $this->uriFactory()->withPort('Foo'); } + public function testWithPortIntegerAsString() + { + $uri = $this->uriFactory()->withPort("199"); + + $this->assertEquals(199, $uri->getPort()); + } + public function testGetPath() { $this->assertEquals('/foo/bar', $this->uriFactory()->getPath());