shlink/module/Core/test/Config/BasePathPrefixerTest.php

92 lines
2.4 KiB
PHP
Raw Normal View History

2019-09-13 21:17:30 +03:00
<?php
2019-10-05 18:26:10 +03:00
2019-09-13 21:17:30 +03:00
declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\Config;
use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Config\BasePathPrefixer;
class BasePathPrefixerTest extends TestCase
{
private BasePathPrefixer $prefixer;
2019-09-13 21:17:30 +03:00
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);
2020-10-04 01:35:14 +03:00
self::assertEquals($expectedRoutes, $routes);
self::assertEquals($expectedMiddlewares, $middlewares);
self::assertEquals([
2019-09-13 21:17:30 +03:00
'domain' => [
'hostname' => $expectedHostname,
],
], $urlShortener);
}
public function provideConfig(): iterable
{
$urlShortener = [
'domain' => [
'hostname' => null,
],
];
yield 'without anything' => [['url_shortener' => $urlShortener], [], [], ''];
2019-09-13 21:17:30 +03:00
yield 'with empty options' => [
[
'routes' => [],
'middleware_pipeline' => [],
'url_shortener' => $urlShortener,
2019-09-13 21:17:30 +03:00
],
[],
[],
'',
];
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',
];
}
}