mirror of
https://github.com/shlinkio/shlink.git
synced 2025-03-14 04:00:57 +03:00
Created BasePathPrefixerTest
This commit is contained in:
parent
d7a3aeb0a2
commit
6e38457655
1 changed files with 85 additions and 0 deletions
85
module/Core/test/Config/BasePathPrefixerTest.php
Normal file
85
module/Core/test/Config/BasePathPrefixerTest.php
Normal file
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioTest\Shlink\Core\Config;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Shlinkio\Shlink\Core\Config\BasePathPrefixer;
|
||||
|
||||
class BasePathPrefixerTest extends TestCase
|
||||
{
|
||||
/** @var BasePathPrefixer */
|
||||
private $prefixer;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->prefixer = new BasePathPrefixer();
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider provideConfig
|
||||
*/
|
||||
public function parsesConfigAsExpected(
|
||||
array $originalConfig,
|
||||
array $expectedRoutes,
|
||||
array $expectedMiddlewares,
|
||||
string $expectedHostname
|
||||
): void {
|
||||
[
|
||||
'routes' => $routes,
|
||||
'middleware_pipeline' => $middlewares,
|
||||
'url_shortener' => $urlShortener,
|
||||
] = ($this->prefixer)($originalConfig);
|
||||
|
||||
$this->assertEquals($expectedRoutes, $routes);
|
||||
$this->assertEquals($expectedMiddlewares, $middlewares);
|
||||
$this->assertEquals([
|
||||
'domain' => [
|
||||
'hostname' => $expectedHostname,
|
||||
],
|
||||
], $urlShortener);
|
||||
}
|
||||
|
||||
public function provideConfig(): iterable
|
||||
{
|
||||
yield 'without anything' => [[], [], [], ''];
|
||||
yield 'with empty options' => [
|
||||
[
|
||||
'routes' => [],
|
||||
'middleware_pipeline' => [],
|
||||
'url_shortener' => [],
|
||||
],
|
||||
[],
|
||||
[],
|
||||
'',
|
||||
];
|
||||
yield 'with non-empty options' => [
|
||||
[
|
||||
'routes' => [
|
||||
['path' => '/something'],
|
||||
['path' => '/something-else'],
|
||||
],
|
||||
'middleware_pipeline' => [
|
||||
['with' => 'no_path'],
|
||||
['path' => '/rest', 'middleware' => []],
|
||||
],
|
||||
'url_shortener' => [
|
||||
'domain' => [
|
||||
'hostname' => 'doma.in',
|
||||
],
|
||||
],
|
||||
'router' => ['base_path' => '/foo/bar'],
|
||||
],
|
||||
[
|
||||
['path' => '/foo/bar/something'],
|
||||
['path' => '/foo/bar/something-else'],
|
||||
],
|
||||
[
|
||||
['with' => 'no_path'],
|
||||
['path' => '/foo/bar/rest', 'middleware' => []],
|
||||
],
|
||||
'doma.in/foo/bar',
|
||||
];
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue