2019-09-13 13:17:30 -05:00
|
|
|
<?php
|
2019-10-05 10:26:10 -05:00
|
|
|
|
2019-09-13 13:17:30 -05:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkioTest\Shlink\Core\Config;
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Shlinkio\Shlink\Core\Config\BasePathPrefixer;
|
|
|
|
|
|
|
|
class BasePathPrefixerTest extends TestCase
|
|
|
|
{
|
2019-12-29 15:48:40 -06:00
|
|
|
private BasePathPrefixer $prefixer;
|
2019-09-13 13:17:30 -05:00
|
|
|
|
2022-09-11 05:02:49 -05:00
|
|
|
protected function setUp(): void
|
2019-09-13 13:17:30 -05:00
|
|
|
{
|
|
|
|
$this->prefixer = new BasePathPrefixer();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @dataProvider provideConfig
|
|
|
|
*/
|
|
|
|
public function parsesConfigAsExpected(
|
|
|
|
array $originalConfig,
|
|
|
|
array $expectedRoutes,
|
|
|
|
array $expectedMiddlewares,
|
|
|
|
): void {
|
2022-03-14 13:26:02 -05:00
|
|
|
['routes' => $routes, 'middleware_pipeline' => $middlewares] = ($this->prefixer)($originalConfig);
|
2019-09-13 13:17:30 -05:00
|
|
|
|
2020-10-03 17:35:14 -05:00
|
|
|
self::assertEquals($expectedRoutes, $routes);
|
|
|
|
self::assertEquals($expectedMiddlewares, $middlewares);
|
2019-09-13 13:17:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public function provideConfig(): iterable
|
|
|
|
{
|
2022-03-14 13:26:02 -05:00
|
|
|
yield 'with empty options' => [['routes' => []], [], []];
|
2019-09-13 13:17:30 -05:00
|
|
|
yield 'with non-empty options' => [
|
|
|
|
[
|
|
|
|
'routes' => [
|
|
|
|
['path' => '/something'],
|
|
|
|
['path' => '/something-else'],
|
|
|
|
],
|
|
|
|
'middleware_pipeline' => [
|
|
|
|
['with' => 'no_path'],
|
|
|
|
['path' => '/rest', 'middleware' => []],
|
|
|
|
],
|
|
|
|
'router' => ['base_path' => '/foo/bar'],
|
|
|
|
],
|
|
|
|
[
|
|
|
|
['path' => '/foo/bar/something'],
|
|
|
|
['path' => '/foo/bar/something-else'],
|
|
|
|
],
|
|
|
|
[
|
|
|
|
['with' => 'no_path'],
|
|
|
|
['path' => '/foo/bar/rest', 'middleware' => []],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|