2018-09-29 09:16:40 +03:00
|
|
|
<?php
|
2019-10-05 18:26:10 +03:00
|
|
|
|
2018-09-29 09:16:40 +03:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkioTest\Shlink\Rest\Authentication;
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Shlinkio\Shlink\Rest\Authentication\AuthenticationPluginManager;
|
|
|
|
use Shlinkio\Shlink\Rest\Authentication\AuthenticationPluginManagerFactory;
|
2019-08-08 18:06:20 +03:00
|
|
|
use Shlinkio\Shlink\Rest\Authentication\Plugin\AuthenticationPluginInterface;
|
2018-09-29 09:16:40 +03:00
|
|
|
use Zend\ServiceManager\ServiceManager;
|
|
|
|
|
|
|
|
class AuthenticationPluginManagerFactoryTest extends TestCase
|
|
|
|
{
|
2019-12-30 00:48:40 +03:00
|
|
|
private AuthenticationPluginManagerFactory $factory;
|
2018-09-29 09:16:40 +03:00
|
|
|
|
2019-02-16 12:53:45 +03:00
|
|
|
public function setUp(): void
|
2018-09-29 09:16:40 +03:00
|
|
|
{
|
|
|
|
$this->factory = new AuthenticationPluginManagerFactory();
|
|
|
|
}
|
|
|
|
|
2019-08-08 18:06:20 +03:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @dataProvider provideConfigs
|
|
|
|
*/
|
|
|
|
public function serviceIsProperlyCreatedWithExpectedPlugins(?array $config, array $expectedPlugins): void
|
2018-09-29 09:16:40 +03:00
|
|
|
{
|
2019-08-08 18:06:20 +03:00
|
|
|
$instance = ($this->factory)(new ServiceManager(['services' => [
|
|
|
|
'config' => $config,
|
|
|
|
]]));
|
|
|
|
|
|
|
|
$this->assertEquals($expectedPlugins, $this->getPlugins($instance));
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getPlugins(AuthenticationPluginManager $pluginManager): array
|
|
|
|
{
|
2019-12-30 01:16:55 +03:00
|
|
|
return (fn () => $this->services)->call($pluginManager);
|
2019-08-08 18:06:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function provideConfigs(): iterable
|
|
|
|
{
|
|
|
|
yield [null, []];
|
|
|
|
yield [[], []];
|
|
|
|
yield [['auth' => []], []];
|
|
|
|
yield [['auth' => [
|
|
|
|
'plugins' => [],
|
|
|
|
]], []];
|
|
|
|
yield [['auth' => [
|
|
|
|
'plugins' => [
|
|
|
|
'services' => $plugins = [
|
|
|
|
'foo' => $this->prophesize(AuthenticationPluginInterface::class)->reveal(),
|
|
|
|
'bar' => $this->prophesize(AuthenticationPluginInterface::class)->reveal(),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
]], $plugins];
|
2018-09-29 09:16:40 +03:00
|
|
|
}
|
|
|
|
}
|