shlink/module/Rest/test/ConfigProviderTest.php

77 lines
2.2 KiB
PHP
Raw Normal View History

2016-07-30 16:17:13 -05:00
<?php
2019-10-05 10:26:10 -05:00
2017-10-12 03:13:20 -05:00
declare(strict_types=1);
2016-07-30 16:17:13 -05:00
namespace ShlinkioTest\Shlink\Rest;
2020-11-22 11:11:31 -06:00
use Laminas\ServiceManager\AbstractFactory\ConfigAbstractFactory;
2017-03-24 14:34:18 -05:00
use PHPUnit\Framework\TestCase;
2016-07-30 16:17:13 -05:00
use Shlinkio\Shlink\Rest\ConfigProvider;
class ConfigProviderTest extends TestCase
{
private ConfigProvider $configProvider;
2016-07-30 16:17:13 -05:00
2019-02-16 03:53:45 -06:00
public function setUp(): void
2016-07-30 16:17:13 -05:00
{
$this->configProvider = new ConfigProvider();
}
2019-02-17 13:28:34 -06:00
/** @test */
public function properConfigIsReturned(): void
2016-07-30 16:17:13 -05:00
{
$config = ($this->configProvider)();
2016-07-30 16:17:13 -05:00
2020-11-22 11:11:31 -06:00
self::assertCount(5, $config);
2020-10-03 17:35:14 -05:00
self::assertArrayHasKey('routes', $config);
self::assertArrayHasKey('dependencies', $config);
2020-11-22 11:11:31 -06:00
self::assertArrayHasKey('auth', $config);
self::assertArrayHasKey('entity_manager', $config);
self::assertArrayHasKey(ConfigAbstractFactory::class, $config);
2016-07-30 16:17:13 -05:00
}
/**
* @test
* @dataProvider provideRoutesConfig
*/
public function routesAreProperlyPrefixed(array $routes, array $expected): void
{
$configProvider = new ConfigProvider(fn () => ['routes' => $routes]);
$config = $configProvider();
2020-10-03 17:35:14 -05:00
self::assertEquals($expected, $config['routes']);
}
public function provideRoutesConfig(): iterable
{
yield 'health action present' => [
[
['path' => '/foo'],
['path' => '/bar'],
['path' => '/baz/foo'],
['path' => '/health'],
],
[
['path' => '/rest/v{version:1|2}/foo'],
['path' => '/rest/v{version:1|2}/bar'],
['path' => '/rest/v{version:1|2}/baz/foo'],
['path' => '/rest/v{version:1|2}/health'],
['path' => '/rest/health', 'name' => ConfigProvider::UNVERSIONED_HEALTH_ENDPOINT_NAME],
],
];
yield 'health action not present' => [
[
['path' => '/foo'],
['path' => '/bar'],
['path' => '/baz/foo'],
],
[
['path' => '/rest/v{version:1|2}/foo'],
['path' => '/rest/v{version:1|2}/bar'],
['path' => '/rest/v{version:1|2}/baz/foo'],
],
];
}
2016-07-30 16:17:13 -05:00
}