Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ManagerTest.php
Go to the documentation of this file.
1 <?php
7 
11 use Magento\Framework\Event\Manager as EventManager;
12 
18 class ManagerTest extends \PHPUnit\Framework\TestCase
19 {
23  protected $invokerMock;
24 
28  protected $eventFactory;
29 
33  protected $event;
34 
38  protected $wrapperFactory;
39 
43  protected $observer;
44 
48  protected $eventConfigMock;
49 
53  protected $eventManager;
54 
59 
60  protected function setUp()
61  {
62  $this->objectManagerHelper = new ObjectManagerHelper($this);
63  $this->invokerMock = $this->createMock(InvokerInterface::class);
64  $this->eventConfigMock = $this->createMock(ConfigInterface::class);
65 
66  $this->eventManager = $this->objectManagerHelper->getObject(
67  EventManager::class,
68  [
69  'invoker' => $this->invokerMock,
70  'eventConfig' => $this->eventConfigMock
71  ]
72  );
73  }
74 
75  public function testDispatch()
76  {
77  $this->eventConfigMock->expects($this->once())
78  ->method('getObservers')
79  ->with('some_eventname')
80  ->willReturn(['observer' => ['instance' => 'class', 'method' => 'method', 'name' => 'observer']]);
81  $this->eventManager->dispatch('some_eventName', ['123']);
82  }
83 
85  {
86  $this->eventConfigMock->expects($this->once())
87  ->method('getObservers')
88  ->with('some_event')
89  ->willReturn([]);
90  $this->invokerMock->expects($this->never())->method('dispatch');
91  $this->eventManager->dispatch('some_event');
92  }
93 }