Passed
Pull Request — master (#448)
by Alejandro
06:34
created

AuthenticationPluginManagerFactoryTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 20
dl 0
loc 46
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 3 1
A provideConfigs() 0 16 1
A getPlugins() 0 5 1
A serviceIsProperlyCreatedWithExpectedPlugins() 0 7 1
1
<?php
2
declare(strict_types=1);
3
4
namespace ShlinkioTest\Shlink\Rest\Authentication;
5
6
use PHPUnit\Framework\TestCase;
7
use Shlinkio\Shlink\Rest\Authentication\AuthenticationPluginManager;
8
use Shlinkio\Shlink\Rest\Authentication\AuthenticationPluginManagerFactory;
9
use Shlinkio\Shlink\Rest\Authentication\Plugin\AuthenticationPluginInterface;
10
use Zend\ServiceManager\ServiceManager;
11
12
class AuthenticationPluginManagerFactoryTest extends TestCase
13
{
14
    /** @var AuthenticationPluginManagerFactory */
15
    private $factory;
16
17
    public function setUp(): void
18
    {
19
        $this->factory = new AuthenticationPluginManagerFactory();
20
    }
21
22
    /**
23
     * @test
24
     * @dataProvider provideConfigs
25
     */
26
    public function serviceIsProperlyCreatedWithExpectedPlugins(?array $config, array $expectedPlugins): void
27
    {
28
        $instance = ($this->factory)(new ServiceManager(['services' => [
29
            'config' => $config,
30
        ]]));
31
32
        $this->assertEquals($expectedPlugins, $this->getPlugins($instance));
33
    }
34
35
    private function getPlugins(AuthenticationPluginManager $pluginManager): array
36
    {
37
        return (function () {
38
            return $this->services;
0 ignored issues
show
Bug Best Practice introduced by
The property services does not exist on ShlinkioTest\Shlink\Rest...luginManagerFactoryTest. Did you maybe forget to declare it?
Loading history...
39
        })->call($pluginManager);
40
    }
41
42
    public function provideConfigs(): iterable
43
    {
44
        yield [null, []];
45
        yield [[], []];
46
        yield [['auth' => []], []];
47
        yield [['auth' => [
48
            'plugins' => [],
49
        ]], []];
50
        yield [['auth' => [
51
            'plugins' => [
52
                'services' => $plugins = [
53
                    'foo' => $this->prophesize(AuthenticationPluginInterface::class)->reveal(),
54
                    'bar' => $this->prophesize(AuthenticationPluginInterface::class)->reveal(),
55
                ],
56
            ],
57
        ]], $plugins];
58
    }
59
}
60