mirror of
https://github.com/wiosna-dev/common-library.git
synced 2026-03-12 09:31:51 +01:00
Add Uri::buildUrl() method
Builds url with given root url and parts of url
This commit is contained in:
@@ -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',
|
||||
'',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user