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

provideConfigs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 16
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 0
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