Commit eb2a6e10 authored by Sebastian De Deyne's avatar Sebastian De Deyne

Path now defaults to a slash; added matches method

parent b455cf17
......@@ -53,7 +53,7 @@ class Url implements UriInterface
$url->port = $parts['port'] ?? null;
$url->user = $parts['user'] ?? '';
$url->password = $parts['pass'] ?? null;
$url->path = $parts['path'] ?? '';
$url->path = $parts['path'] ?? '/';
$url->query = QueryParameterBag::fromString($parts['query'] ?? '');
$url->fragment = $parts['fragment'] ?? '';
......@@ -279,6 +279,11 @@ class Url implements UriInterface
return $url;
}
public function matches(Url $url): bool
{
return $this->__toString() === $url->__toString();
}
public function __toString()
{
$url = '';
......
......@@ -57,7 +57,7 @@ class UrlImmutableTest extends \PHPUnit_Framework_TestCase
$clone = $url->withPath('/opensource');
$this->assertEquals('', $url->getPath());
$this->assertEquals('/', $url->getPath());
$this->assertEquals('/opensource', $clone->getPath());
}
......
<?php
namespace Spatie\Url\Test;
use Spatie\Url\Url;
class UrlMatchesTest extends \PHPUnit_Framework_TestCase
{
/** @test */
public function it_can_check_if_it_matches_another_url()
{
$url = Url::fromString('https://spatie.be');
$this->assertTrue($url->matches(Url::fromString('https://spatie.be/')));
}
/** @test */
public function it_can_check_if_it_doesnt_match_another_url()
{
$url = Url::fromString('https://spatie.be');
$this->assertFalse($url->matches(Url::fromString('https://spatie.be/opensource')));
}
}
......@@ -53,7 +53,7 @@ class UrlParseTest extends \PHPUnit_Framework_TestCase
{
$url = Url::fromString('https://spatie.be');
$this->assertEquals('', $url->getPath());
$this->assertEquals('/', $url->getPath());
}
/** @test */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment