setServiceLocator(new ServiceManager($config)); $this->assertInstanceOf(EventManager::class, $eventManager); return $eventManager; //no cleanup required, not persisted } /** * @depends testInit */ public function testAttachOne($eventManager) { $callable = $this->prophesize(EmptyClass::class); $callable->testfunction(Argument::any())->should(new CallTimesPrediction(1)); $eventManager->attach('testEvent', [$callable->reveal(), 'testfunction']); $eventManager->trigger('testEvent'); } /** * @depends testInit */ public function testAttachMultiple($eventManager) { $callable = $this->prophesize(EmptyClass::class); $callable->testfunction(Argument::any())->should(new CallTimesPrediction(2)); $eventManager->attach(['testEvent1','testEvent2'], [$callable->reveal(), 'testfunction']); $eventManager->trigger('testEvent1'); $eventManager->trigger('testEvent2'); $eventManager->trigger('testEvent3'); } /** * @depends testInit */ public function testTriggerEventObj($eventManager) { $genericEvent = new GenericEvent('objEvent', ['param1' => '1']); $callable = $this->prophesize(EmptyClass::class); $callable->testfunction($genericEvent)->should(new CallTimesPrediction(1)); $eventManager->attach($genericEvent->getName(), [$callable->reveal(), 'testfunction']); $eventManager->trigger($genericEvent); $genericEvent2 = new GenericEvent('objEvent2', ['param1' => '2']); $eventManager->attach($genericEvent2->getName(), [EmptyClassService::class, 'testfunction']); $eventManager->trigger($genericEvent2); $this->assertTrue(EmptyClassService::$called); } /** * @depends testInit */ public function testDetach($eventManager) { $callable = $this->prophesize(EmptyClass::class); $callable->testfunction(Argument::any())->should(new CallTimesPrediction(1)); $callable->testfunction2(Argument::any())->should(new CallTimesPrediction(1)); $callable->testfunction3(Argument::any())->should(new CallTimesPrediction(1)); $revelation = $callable->reveal(); $eventManager->attach(['testEvent'], [$revelation, 'testfunction']); $eventManager->attach(['testEvent'], [$revelation, 'testfunction2']); $eventManager->attach(['testEvent'], [$revelation, 'testfunction3']); $eventManager->trigger('testEvent'); $eventManager->detach(['testEvent'], [$revelation, 'testfunction']); $eventManager->detach(['testEvent'], [$revelation, 'testfunction2']); $eventManager->detach(['testEvent'], [$revelation, 'testfunction3']); $eventManager->trigger('testEvent'); } }