Add Uri::buildUrl() method

Builds url with given root url and parts of url
This commit is contained in:
Meritoo
2019-08-28 16:01:27 +02:00
parent 891411e231
commit f7a8da0550
10 changed files with 140 additions and 2 deletions

View File

@@ -19,7 +19,7 @@ use Meritoo\Common\Utilities\Uri;
* @copyright Meritoo <http://www.meritoo.pl>
*
* @internal
* @covers \Meritoo\Common\Utilities\Uri
* @covers \Meritoo\Common\Utilities\Uri
*/
class UriTest extends BaseTestCase
{
@@ -255,6 +255,18 @@ class UriTest extends BaseTestCase
self::assertEquals($expectedUrl, Uri::getSecuredUrl($url, $user, $password));
}
/**
* @param string $expected
* @param string $rootUrl
* @param string ...$urlParts
*
* @dataProvider provideRootUrlAndUrlParts
*/
public function testBuildUrl(string $expected, string $rootUrl, string ...$urlParts): void
{
static::assertSame($expected, Uri::buildUrl($rootUrl, ...$urlParts));
}
/**
* Provides url to replenish protocol
*
@@ -372,4 +384,56 @@ class UriTest extends BaseTestCase
'http://john:pass123@lorem.com/contact',
];
}
public function provideRootUrlAndUrlParts(): ?Generator
{
yield[
'',
'',
];
yield[
'',
'',
'',
];
yield[
'http://my.example',
'http://my.example',
'',
];
yield[
'http://my.example',
'http://my.example',
'',
'',
];
yield[
'http://my.example//test/12/test/',
'http://my.example',
'',
'test',
'12/test',
'',
];
yield[
'http://my.example//test/12/test',
'http://my.example',
'',
'test/',
'12/test/',
];
yield[
'http://my.example/test/12/test/',
'http://my.example',
'/test/',
'/12/test',
'',
];
}
}