Ejemplo n.º 1
0
 public function testTriggerMergesPrioritiesOfStaticAndInstanceListeners()
 {
     $test = (object) array('results' => array());
     StaticEventManager::getInstance()->attach(
         'ZendTest\EventManager\TestAsset\ClassWithEvents', 
         'foo', 
         function ($e) use ($test) {
             $test->results[] = 'static';
         },
         100
     );
     $class = new TestAsset\ClassWithEvents();
     $class->events()->attach('foo', function ($e) use ($test) {
         $test->results[] = 'local';
     }, -100);
     $class->foo();
     $this->assertEquals(array('static', 'local'), $test->results);
 }
Ejemplo n.º 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);
 }