|
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); |
|
|
|
|
|
|
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
|
|
|
|
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.