Skip to content

Commit

Permalink
Merge branch 'url' into 5.2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
natanfelles committed Jun 28, 2023
2 parents d8316fd + 344b94c commit 561a794
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
6 changes: 1 addition & 5 deletions src/URL.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,8 @@ public function getPass() : ?string
#[Pure]
public function getPath() : string
{
$count = \count($this->pathSegments);
$path = \implode('/', $this->pathSegments);
if ($count === 1 && $path === '') {
return '/';
}
return $path === '' ? '' : '/' . $path;
return $path === '' ? '/' : '/' . $path;
}

/**
Expand Down
13 changes: 12 additions & 1 deletion tests/URLTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function setUp() : void
public function testSameUrl() : void
{
$url = 'http://domain.tld';
self::assertSame($url, (new URL($url))->__toString());
self::assertNotSame($url, (new URL($url))->__toString());
$url = 'http://domain.tld/';
self::assertSame($url, (new URL($url))->__toString());
$url = 'http://domain.tld/foo';
Expand All @@ -41,6 +41,15 @@ public function testSameUrl() : void
self::assertSame($url, (new URL($url))->__toString());
}

public function testPathEndsWithBar() : void
{
$url = 'http://domain.tld';
self::assertSame(
$url . '/',
(new URL($url))->__toString()
);
}

public function testBaseUrl() : void
{
self::assertSame('http://domain.tld:8080/', $this->url->getBaseUrl());
Expand Down Expand Up @@ -112,6 +121,8 @@ public function testPath() : void
self::assertSame('/a/b/c/', $this->url->getPath());
$this->url->setPath('/a/b/c/');
self::assertSame('/a/b/c/', $this->url->getPath());
$this->url->setPathSegments([]);
self::assertSame('/', $this->url->getPath());
$this->url->setPathSegments(['hello', 'bye']);
self::assertSame('/hello/bye', $this->url->getPath());
$this->url->setPathSegments(['hello', 'bye', '']);
Expand Down

0 comments on commit 561a794

Please sign in to comment.