ModuleDefinedServicesTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 100
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testModuleDefinedServices() 0 4 1
A testModuleFetchedService() 0 4 1
A testModuleInvalidService() 0 6 1
A getServicesThatShouldBeDefined() 0 28 1
A getServicesThatCanBeFetched() 0 6 1
A getServicesThatCannotBeFetched() 0 12 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DoctrineModuleTest\ServiceFactory;
6
7
use DoctrineModuleTest\ServiceManagerFactory;
8
use Laminas\ServiceManager\ServiceLocatorInterface;
9
use PHPUnit\Framework\TestCase;
10
11
/**
12
 * Test that verifies that services are defined correctly
13
 *
14
 * @link    http://www.doctrine-project.org/
15
 */
16
class ModuleDefinedServicesTest extends TestCase
17
{
18
    /** @var ServiceLocatorInterface */
19
    protected $serviceManager;
20
21
    protected function setUp() : void
22
    {
23
        $this->serviceManager = ServiceManagerFactory::getServiceManager();
24
    }
25
26
    /**
27
     * Verifies that the module defines the correct services
28
     *
29
     * @dataProvider getServicesThatShouldBeDefined
30
     */
31
    public function testModuleDefinedServices(string $serviceName, bool $defined) : void
32
    {
33
        $this->assertSame($defined, $this->serviceManager->has($serviceName));
34
    }
35
36
    /**
37
     * Verifies that the module defines the correct services
38
     *
39
     * @dataProvider getServicesThatCanBeFetched
40
     */
41
    public function testModuleFetchedService(string $serviceName, string $expectedClass) : void
42
    {
43
        $this->assertInstanceOf($expectedClass, $this->serviceManager->get($serviceName));
44
    }
45
46
    /**
47
     * Verifies that the module defines the correct services
48
     *
49
     * @dataProvider getServicesThatCannotBeFetched
50
     */
51
    public function testModuleInvalidService(string $serviceName) : void
52
    {
53
        $this->expectException('Laminas\ServiceManager\Exception\ServiceNotFoundException');
54
55
        $this->serviceManager->get($serviceName);
56
    }
57
58
    /**
59
     * @return mixed[][]
60
     */
61
    public function getServicesThatShouldBeDefined() : array
62
    {
63
        return [
64
            ['doctrine.cache.array', true],
65
            ['doctrine.cache.apc', true],
66
            ['doctrine.cache.filesystem', true],
67
            ['doctrine.cache.memcache', true],
68
            ['doctrine.cache.memcached', true],
69
            ['doctrine.cache.redis', true],
70
            ['doctrine.cache.wincache', true],
71
            ['doctrine.cache.xcache', true],
72
            ['doctrine.cache.zenddata', true],
73
            ['doctrine.authenticationadapter.orm_default', true],
74
            ['doctrine.authenticationstorage.orm_default', true],
75
            ['doctrine.authenticationservice.orm_default', true],
76
            ['doctrine.authenticationadapter.odm_default', true],
77
            ['doctrine.authenticationstorage.odm_default', true],
78
            ['doctrine.authenticationservice.odm_default', true],
79
            ['foo', false],
80
            ['foo.bar', false],
81
            ['foo.bar.baz', false],
82
            ['doctrine', false],
83
            ['doctrine.foo', false],
84
            ['doctrine.foo.bar', false],
85
            ['doctrine.cache.bar', false],
86
            //['doctrine.cache.laminascachestorage'],
87
        ];
88
    }
89
90
    /**
91
     * @return string[][]
92
     */
93
    public function getServicesThatCanBeFetched() : array
94
    {
95
        return [
96
            ['doctrine.cache.array', 'Doctrine\Common\Cache\ArrayCache'],
97
        ];
98
    }
99
100
    /**
101
     * @return string[][]
102
     */
103
    public function getServicesThatCannotBeFetched() : array
104
    {
105
        return [
106
            ['foo'],
107
            ['foo.bar'],
108
            ['foo.bar.baz'],
109
            ['doctrine'],
110
            ['doctrine.foo'],
111
            ['doctrine.foo.bar'],
112
            ['doctrine.cache.bar'],
113
        ];
114
    }
115
}
116