public function testTriggerMergesPrioritiesOfStaticAndInstanceListeners()
 {
     $test = (object) array('results' => array());
     $events = StaticEventManager::getInstance();
     $events->attach('ZendTest\\EventManager\\TestAsset\\ClassWithEvents', 'foo', function ($e) use($test) {
         $test->results[] = 'static';
     }, 100);
     $class = new TestAsset\ClassWithEvents();
     $class->getEventManager()->attach('foo', function ($e) use($test) {
         $test->results[] = 'local';
     }, -100);
     $class->getEventManager()->setSharedManager($events);
     $class->foo();
     $this->assertEquals(array('static', 'local'), $test->results);
 }
Exemple #2
0
 public function testCanPassAlternateStaticConnectionsHolder()
 {
     $counter = (object) array('count' => 0);
     StaticEventManager::getInstance()->attach('ZendTest\\EventManager\\TestAsset\\ClassWithEvents', 'foo', function ($e) use($counter) {
         $counter->count++;
     });
     $mockStaticEvents = new TestAsset\StaticEventsMock();
     $class = new TestAsset\ClassWithEvents();
     $class->events()->setStaticConnections($mockStaticEvents);
     $this->assertSame($mockStaticEvents, $class->events()->getStaticConnections());
     $class->foo();
     $this->assertEquals(0, $counter->count);
 }