public function testSetsSharedEventManager()
 {
     $sharedEvents = new SharedEventManager();
     $events = $this->getMockBuilder('\\Zend\\EventManager\\EventManager')->disableOriginalConstructor()->setMethods(['setIdentifiers', 'setEventClass', 'setSharedManager'])->getMock();
     $events->expects($this->once())->method('setSharedManager')->with($sharedEvents);
     $services = $this->getServiceManagerMock($events, ['SharedEventManager' => $sharedEvents]);
     $this->setTargetConfig(['configure' => true]);
     $this->target->createServiceWithName($services, 'irrelevant', 'Test/Events');
 }
 public function testNormalizeListenerOptionsWithArrayHashSpecification()
 {
     $listenerMock = new \stdClass();
     $singleEvent = ['singleEvent'];
     $priorityEvent = ['prioEvent' => 10];
     $methodEvent = ['methodEvent' => 'method'];
     $singleAndPriorityAndMethodEvent = ['single', 'priority' => 10, 'method' => 'method'];
     $verboseEvent = ['verbose' => ['method' => 'method', 'priority' => 20]];
     $verboseFullEvent = ['verbose' => ['method' => ['method1', 'method2' => 25], 'priority' => 30]];
     $listeners = ['Test1' => ['events' => $singleEvent], 'Test2' => ['events' => $priorityEvent], 'Test3' => ['events' => $methodEvent], 'Test4' => ['events' => $singleEvent, 'priority' => 12], 'Test5' => ['events' => $priorityEvent, 'priority' => 12], 'Test6' => ['events' => $methodEvent, 'priority' => 12], 'Test7' => ['events' => $singleEvent, 'method' => 'method'], 'Test8' => ['events' => $priorityEvent, 'method' => 'method'], 'Test9' => ['events' => $methodEvent, 'method' => 'method2'], 'Test10' => ['events' => $singleEvent, 'method' => 'method', 'priority' => 12], 'Test11' => ['events' => $priorityEvent, 'method' => 'method2', 'priority' => 12], 'Test12' => ['events' => $methodEvent, 'method' => 'method2', 'priority' => 12], 'Test13' => ['events' => $singleAndPriorityAndMethodEvent, 'method' => 'listenerMethod'], 'Test14' => ['events' => $verboseEvent], 'Test15' => ['events' => $verboseFullEvent], 'Test16' => ['events' => $singleEvent, 'lazy' => true]];
     $servicesCfg = array_fill_keys(['Test1', 'Test2', 'Test3', 'Test4', 'Test5', 'Test6', 'Test7', 'Test8', 'Test9', 'Test10', 'Test11', 'Test12', 'Test13', 'Test14', 'Test15'], $listenerMock);
     $expectedLazyListeners = [['service' => 'Test16', 'event' => $singleEvent, 'method' => null, 'priority' => 0]];
     $lazyAggregateMock = $this->getLazyAggregateMock();
     $lazyAggregateMock->expects($this->once())->method('setListeners')->with($expectedLazyListeners)->willReturnSelf();
     $this->setTargetListenerConfig($listeners);
     $services = $this->getServiceManagerMock($servicesCfg, true);
     $this->events->expects($this->exactly(18))->method('attach')->withConsecutive([$singleEvent, $listenerMock, 0], [['prioEvent'], $listenerMock, 10], [['methodEvent'], [$listenerMock, 'method'], 0], [$singleEvent, $listenerMock, 12], [['prioEvent'], $listenerMock, 10], [['methodEvent'], [$listenerMock, 'method'], 12], [$singleEvent, [$listenerMock, 'method'], 0], [['prioEvent'], [$listenerMock, 'method'], 10], [['methodEvent'], [$listenerMock, 'method'], 0], [$singleEvent, [$listenerMock, 'method'], 12], [['prioEvent'], [$listenerMock, 'method2'], 10], [['methodEvent'], [$listenerMock, 'method'], 12], [['single'], [$listenerMock, 'listenerMethod'], 0], [['priority'], [$listenerMock, 'listenerMethod'], 10], [['method'], [$listenerMock, 'method'], 0], [['verbose'], [$listenerMock, 'method'], 20], [['verbose'], [$listenerMock, 'method1'], 30], [['verbose'], [$listenerMock, 'method2'], 25]);
     $this->target->createServiceWithName($services, '', '');
 }
 public function testDeterminesIfItCanCreateAnEventManagerByName()
 {
     $services = new ServiceManager();
     $this->assertTrue($this->target->canCreateServiceWithName($services, 'irrelevant', 'Any.string/Value/Events'), 'Checking correct name failed.');
     $this->assertFalse($this->target->canCreateServiceWithName($services, 'irrelevant', 'Any.string.not.ending/in/Events.but has it in the middle!'), 'Checking invalid name failed.');
 }