Completed
Push — master ( e0017c...6b1304 )
by Tom
14s queued 11s
created

Service/EventManagerFactoryTest.php (9 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
declare(strict_types=1);
4
5
namespace DoctrineModuleTest\Service;
6
7
use DoctrineModule\Service\EventManagerFactory;
8
use DoctrineModuleTest\Service\TestAsset\DummyEventSubscriber;
9
use Laminas\ServiceManager\ServiceManager;
10
use PHPUnit\Framework\TestCase as BaseTestCase;
11
12
/**
13
 * Base test case to be used when a service manager instance is required
14
 */
15
class EventManagerFactoryTest extends BaseTestCase
16
{
17
    public function testWillInstantiateFromFQCN() : void
18
    {
19
        $name           = 'eventManagerFactory';
20
        $factory        = new EventManagerFactory($name);
21
        $serviceManager = new ServiceManager();
22
        $serviceManager->setService(
23
            'config',
24
            [
25
                'doctrine' => [
26
                    'eventmanager' => [
27
                        $name => [
28
                            'subscribers' => [
29
                                __NAMESPACE__ . '\TestAsset\DummyEventSubscriber',
30
                            ],
31
                        ],
32
                    ],
33
                ],
34
            ]
35
        );
36
37
        /* $var $eventManager \Doctrine\Common\EventManager */
38
        $eventManager = $factory->createService($serviceManager);
39
        $this->assertInstanceOf('Doctrine\Common\EventManager', $eventManager);
0 ignored issues
show
The method assertInstanceOf() does not seem to exist on object<DoctrineModuleTes...ventManagerFactoryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
40
41
        $listeners = $eventManager->getListeners('dummy');
42
        $this->assertCount(1, $listeners);
0 ignored issues
show
The method assertCount() does not seem to exist on object<DoctrineModuleTes...ventManagerFactoryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
43
    }
44
45
    public function testWillAttachEventListenersFromConfiguredInstances() : void
46
    {
47
        $name           = 'eventManagerFactory';
48
        $factory        = new EventManagerFactory($name);
49
        $subscriber     = new DummyEventSubscriber();
50
        $serviceManager = new ServiceManager();
51
        $serviceManager->setService(
52
            'config',
53
            [
54
                'doctrine' => [
55
                    'eventmanager' => [
56
                        $name => [
57
                            'subscribers' => [$subscriber],
58
                        ],
59
                    ],
60
                ],
61
            ]
62
        );
63
64
        /* $var $eventManager \Doctrine\Common\EventManager */
65
        $eventManager = $factory->createService($serviceManager);
66
        $this->assertInstanceOf('Doctrine\Common\EventManager', $eventManager);
0 ignored issues
show
The method assertInstanceOf() does not seem to exist on object<DoctrineModuleTes...ventManagerFactoryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
67
68
        $listeners = $eventManager->getListeners();
69
        $this->assertArrayHasKey('dummy', $listeners);
0 ignored issues
show
The method assertArrayHasKey() does not seem to exist on object<DoctrineModuleTes...ventManagerFactoryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
70
        $listeners = $eventManager->getListeners('dummy');
71
        $this->assertContains($subscriber, $listeners);
0 ignored issues
show
The method assertContains() does not seem to exist on object<DoctrineModuleTes...ventManagerFactoryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
72
    }
73
74
    public function testWillAttachEventListenersFromServiceManagerAlias() : void
75
    {
76
        $name           = 'eventManagerFactory';
77
        $factory        = new EventManagerFactory($name);
78
        $subscriber     = new DummyEventSubscriber();
79
        $serviceManager = new ServiceManager();
80
        $serviceManager->setService('dummy-subscriber', $subscriber);
81
        $serviceManager->setService(
82
            'config',
83
            [
84
                'doctrine' => [
85
                    'eventmanager' => [
86
                        $name => [
87
                            'subscribers' => ['dummy-subscriber'],
88
                        ],
89
                    ],
90
                ],
91
            ]
92
        );
93
94
        /* $var $eventManager \Doctrine\Common\EventManager */
95
        $eventManager = $factory->createService($serviceManager);
96
        $this->assertInstanceOf('Doctrine\Common\EventManager', $eventManager);
0 ignored issues
show
The method assertInstanceOf() does not seem to exist on object<DoctrineModuleTes...ventManagerFactoryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
97
98
        $listeners = $eventManager->getListeners();
99
        $this->assertArrayHasKey('dummy', $listeners);
0 ignored issues
show
The method assertArrayHasKey() does not seem to exist on object<DoctrineModuleTes...ventManagerFactoryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
100
        $listeners = $eventManager->getListeners('dummy');
101
        $this->assertContains($subscriber, $listeners);
0 ignored issues
show
The method assertContains() does not seem to exist on object<DoctrineModuleTes...ventManagerFactoryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
102
    }
103
104
    public function testWillRefuseNonExistingSubscriber() : void
105
    {
106
        $name           = 'eventManagerFactory';
107
        $factory        = new EventManagerFactory($name);
108
        $serviceManager = new ServiceManager();
109
        $serviceManager->setService(
110
            'config',
111
            [
112
                'doctrine' => [
113
                    'eventmanager' => [
114
                        $name => [
115
                            'subscribers' => ['non-existing-subscriber'],
116
                        ],
117
                    ],
118
                ],
119
            ]
120
        );
121
122
        $this->expectException('InvalidArgumentException');
0 ignored issues
show
The method expectException() does not seem to exist on object<DoctrineModuleTes...ventManagerFactoryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
123
        $factory->createService($serviceManager);
124
    }
125
}
126