|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace ShlinkioTest\Shlink\Rest; |
|
6
|
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
use Shlinkio\Shlink\Rest\ConfigProvider; |
|
9
|
|
|
|
|
10
|
|
|
class ConfigProviderTest extends TestCase |
|
11
|
|
|
{ |
|
12
|
|
|
private ConfigProvider $configProvider; |
|
13
|
|
|
|
|
14
|
|
|
public function setUp(): void |
|
15
|
|
|
{ |
|
16
|
|
|
$this->configProvider = new ConfigProvider(); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
/** @test */ |
|
20
|
|
|
public function properConfigIsReturned(): void |
|
21
|
|
|
{ |
|
22
|
|
|
$config = ($this->configProvider)(); |
|
23
|
|
|
|
|
24
|
|
|
$this->assertArrayHasKey('routes', $config); |
|
25
|
|
|
$this->assertArrayHasKey('dependencies', $config); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @test |
|
30
|
|
|
* @dataProvider provideRoutesConfig |
|
31
|
|
|
*/ |
|
32
|
|
|
public function routesAreProperlyPrefixed(array $routes, array $expected): void |
|
33
|
|
|
{ |
|
34
|
|
|
$configProvider = new ConfigProvider(fn () => ['routes' => $routes]); |
|
35
|
|
|
|
|
36
|
|
|
$config = $configProvider(); |
|
37
|
|
|
|
|
38
|
|
|
$this->assertEquals($expected, $config['routes']); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function provideRoutesConfig(): iterable |
|
42
|
|
|
{ |
|
43
|
|
|
yield 'health action present' => [ |
|
44
|
|
|
[ |
|
45
|
|
|
['path' => '/foo'], |
|
46
|
|
|
['path' => '/bar'], |
|
47
|
|
|
['path' => '/baz/foo'], |
|
48
|
|
|
['path' => '/health'], |
|
49
|
|
|
], |
|
50
|
|
|
[ |
|
51
|
|
|
['path' => '/rest/v{version:1|2}/foo'], |
|
52
|
|
|
['path' => '/rest/v{version:1|2}/bar'], |
|
53
|
|
|
['path' => '/rest/v{version:1|2}/baz/foo'], |
|
54
|
|
|
['path' => '/rest/v{version:1|2}/health'], |
|
55
|
|
|
['path' => '/rest/health', 'name' => ConfigProvider::UNVERSIONED_HEALTH_ENDPOINT_NAME], |
|
56
|
|
|
], |
|
57
|
|
|
]; |
|
58
|
|
|
yield 'health action not present' => [ |
|
59
|
|
|
[ |
|
60
|
|
|
['path' => '/foo'], |
|
61
|
|
|
['path' => '/bar'], |
|
62
|
|
|
['path' => '/baz/foo'], |
|
63
|
|
|
], |
|
64
|
|
|
[ |
|
65
|
|
|
['path' => '/rest/v{version:1|2}/foo'], |
|
66
|
|
|
['path' => '/rest/v{version:1|2}/bar'], |
|
67
|
|
|
['path' => '/rest/v{version:1|2}/baz/foo'], |
|
68
|
|
|
], |
|
69
|
|
|
]; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|