Passed
Push — main ( 3b40c1...b711d3 )
by Peter
07:24
created

EventDispatcherBootstrapperTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 44
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testRegisterBindings() 0 20 1
A setUp() 0 9 1
A tearDown() 0 5 1
1
<?php
2
3
namespace AbterPhp\Framework\Bootstrappers\Events;
4
5
use AbterPhp\Framework\Module\Manager;
6
use Opulence\Events\Dispatchers\EventRegistry;
7
use Opulence\Events\Dispatchers\IEventDispatcher;
8
use Opulence\Ioc\Container;
9
use PHPUnit\Framework\TestCase;
10
11
class EventDispatcherBootstrapperTest extends TestCase
12
{
13
    protected EventDispatcherBootstrapper $sut;
14
15
    protected Manager $moduleManagerMock;
16
17
    public function setUp(): void
18
    {
19
        global $abterModuleManager;
20
21
        $this->sut = new EventDispatcherBootstrapper();
22
23
        $this->moduleManagerMock = $this->getMockBuilder(Manager::class)->disableOriginalConstructor()->getMock();
24
25
        $abterModuleManager = $this->moduleManagerMock;
26
    }
27
28
    public function tearDown(): void
29
    {
30
        global $abterModuleManager;
31
32
        $abterModuleManager = null;
33
    }
34
35
    public function testRegisterBindings()
36
    {
37
        $listenerName = 'foo';
38
        $events1      = [$listenerName => [fn() => null]];
39
        $events2      = [$listenerName => [fn() => null]];
40
41
        $this->sut->setBaseEvents($events1);
42
        $this->moduleManagerMock->expects($this->once())->method('getEvents')->willReturn($events2);
0 ignored issues
show
Bug introduced by
The method expects() does not exist on AbterPhp\Framework\Module\Manager. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

42
        $this->moduleManagerMock->/** @scrutinizer ignore-call */ 
43
                                  expects($this->once())->method('getEvents')->willReturn($events2);

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
        $container = new Container();
45
46
        $this->sut->registerBindings($container);
47
48
        $actual = $container->resolve(IEventDispatcher::class);
49
        $this->assertInstanceOf(IEventDispatcher::class, $actual);
50
51
        /** @var EventRegistry $actual */
52
        $actual = $container->resolve(EventRegistry::class);
53
        $this->assertInstanceOf(EventRegistry::class, $actual);
54
        $this->assertCount(2, $actual->getListeners($listenerName));
55
    }
56
}
57