Centralized how routes are configured to support multi-segment slugs

This commit is contained in:
Alejandro Celaya
2022-08-06 09:30:13 +02:00
parent 4629f1b03f
commit 16bd368a58
10 changed files with 113 additions and 46 deletions

View File

@@ -0,0 +1,60 @@
<?php
declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\Config;
use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Config\MultiSegmentSlugProcessor;
class MultiSegmentSlugProcessorTest extends TestCase
{
private MultiSegmentSlugProcessor $processor;
protected function setUp(): void
{
$this->processor = new MultiSegmentSlugProcessor();
}
/**
* @test
* @dataProvider provideConfigs
*/
public function parsesRoutesAsExpected(array $config, array $expectedRoutes): void
{
self::assertEquals($expectedRoutes, ($this->processor)($config)['routes'] ?? []);
}
public function provideConfigs(): iterable
{
yield [[], []];
yield [['url_shortener' => []], []];
yield [['url_shortener' => ['multi_segment_slugs_enabled' => false]], []];
yield [
[
'url_shortener' => ['multi_segment_slugs_enabled' => false],
'routes' => $routes = [
['path' => '/foo'],
['path' => '/bar/{shortCode}'],
['path' => '/baz/{shortCode}/foo'],
],
],
$routes,
];
yield [
[
'url_shortener' => ['multi_segment_slugs_enabled' => true],
'routes' => [
['path' => '/foo'],
['path' => '/bar/{shortCode}'],
['path' => '/baz/{shortCode}/foo'],
],
],
[
['path' => '/foo'],
['path' => '/bar/{shortCode:.+}'],
['path' => '/baz/{shortCode:.+}/foo'],
],
];
}
}