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