Ejemplo n.º 1
0
 /**
  * Test getter and setters.
  */
 public function testGettersAndSetters()
 {
     $subject = new \Threaded();
     $arguments = new \Threaded();
     $event = new Event($subject, $arguments);
     $this->assertFalse($event->isPropagationStopped());
     $event->stopPropagation();
     $this->assertTrue($event->isPropagationStopped());
     $arguments = new \Threaded();
     $event->setArguments($arguments);
     $this->assertSame($arguments, $event->getArguments());
 }
Ejemplo n.º 2
0
 public function testPropagation()
 {
     // Initializes dispatcher
     $dispatcher = new EventDispatcher();
     // Initializes two listener objects.
     $markers = new \Threaded();
     // Initializes two listeners.
     $listener1 = [new MarkerListener($markers), 'mark'];
     $listener2 = [new MarkerListener($markers), 'mark'];
     // Binds both listeners to 'event.1'
     $dispatcher->addListener('event.1', $listener1);
     $dispatcher->addListener('event.1', $listener2);
     // Initializes an event and stops the propagation.
     $event = new Event();
     $event->stopPropagation();
     // Dispatches 'event.1'
     $dispatcher->dispatch('event.1', $event);
     // Asserts that only listener1 is called.
     // Listener2 is skiped because the event propagation has been stopped.
     $this->assertSame($listener1[0], $markers[0]);
     $this->assertNull($markers[1]);
 }