mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Improved Rest's ConfigProvider test to kill more mutants
This commit is contained in:
parent
fc5904e743
commit
57070ef155
@ -4,19 +4,26 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Shlinkio\Shlink\Rest;
|
namespace Shlinkio\Shlink\Rest;
|
||||||
|
|
||||||
use Zend\Config\Factory;
|
use function Shlinkio\Shlink\Common\loadConfigFromGlob;
|
||||||
use Zend\Stdlib\Glob;
|
|
||||||
|
|
||||||
use function sprintf;
|
use function sprintf;
|
||||||
|
|
||||||
class ConfigProvider
|
class ConfigProvider
|
||||||
{
|
{
|
||||||
private const ROUTES_PREFIX = '/rest/v{version:1|2}';
|
private const ROUTES_PREFIX = '/rest/v{version:1|2}';
|
||||||
|
|
||||||
|
/** @var callable */
|
||||||
|
private $loadConfig;
|
||||||
|
|
||||||
|
public function __construct(?callable $loadConfig = null)
|
||||||
|
{
|
||||||
|
$this->loadConfig = $loadConfig ?? function (string $glob) {
|
||||||
|
return loadConfigFromGlob($glob);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public function __invoke()
|
public function __invoke()
|
||||||
{
|
{
|
||||||
/** @var array $config */
|
$config = ($this->loadConfig)(__DIR__ . '/../config/{,*.}config.php');
|
||||||
$config = Factory::fromFiles(Glob::glob(__DIR__ . '/../config/{,*.}config.php', Glob::GLOB_BRACE));
|
|
||||||
return $this->applyRoutesPrefix($config);
|
return $this->applyRoutesPrefix($config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,9 +20,31 @@ class ConfigProviderTest extends TestCase
|
|||||||
/** @test */
|
/** @test */
|
||||||
public function properConfigIsReturned(): void
|
public function properConfigIsReturned(): void
|
||||||
{
|
{
|
||||||
$config = $this->configProvider->__invoke();
|
$config = ($this->configProvider)();
|
||||||
|
|
||||||
$this->assertArrayHasKey('routes', $config);
|
$this->assertArrayHasKey('routes', $config);
|
||||||
$this->assertArrayHasKey('dependencies', $config);
|
$this->assertArrayHasKey('dependencies', $config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function routesAreProperlyPrefixed(): void
|
||||||
|
{
|
||||||
|
$configProvider = new ConfigProvider(function () {
|
||||||
|
return [
|
||||||
|
'routes' => [
|
||||||
|
['path' => '/foo'],
|
||||||
|
['path' => '/bar'],
|
||||||
|
['path' => '/baz/foo'],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
});
|
||||||
|
|
||||||
|
$config = $configProvider();
|
||||||
|
|
||||||
|
$this->assertEquals([
|
||||||
|
['path' => '/rest/v{version:1|2}/foo'],
|
||||||
|
['path' => '/rest/v{version:1|2}/bar'],
|
||||||
|
['path' => '/rest/v{version:1|2}/baz/foo'],
|
||||||
|
], $config['routes']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user