예제 #1
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]);
 }
예제 #2
0
 /**
  * Tests arguments related methods.
  *
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage Argument "none" not found.
  */
 public function testArguments()
 {
     $subject = new \Threaded();
     $arguments = new \Threaded();
     $event = new Event($subject, $arguments);
     $event->setArgument('scalar', 'scalarValue');
     $event->setArgument('array', ['a', 'b', 'c']);
     $foo = new \Stdclass();
     $foo->value = 'plain value';
     $event->setArgument('plain', $foo);
     $bar = new \Threaded();
     $bar['value'] = 'threaded value';
     $event->setArgument('threaded', $bar);
     $this->assertTrue($event->hasArgument('scalar'));
     $this->assertTrue($event->hasArgument('array'));
     $this->assertTrue($event->hasArgument('plain'));
     $this->assertTrue($event->hasArgument('threaded'));
     $this->assertEquals('scalarValue', $event->getArgument('scalar'));
     $this->assertSame(['a', 'b', 'c'], array_values((array) $event->getArgument('array')));
     $this->assertEquals($foo, $event->getArgument('plain'));
     $this->assertNotSame($foo, $event->getArgument('plain'));
     $this->assertSame($bar, $event->getArgument('threaded'));
     $event->getArgument('none');
 }