Open Monograph Press  3.3.0
AbstractHasDispatcherTest.php
1 <?php
2 
3 namespace Guzzle\Tests\Common;
4 
8 
13 {
15  {
16  $this->assertEquals(array(), AbstractHasDispatcher::getAllEvents());
17  }
18 
20  {
21  $d = new EventDispatcher();
22  $mock = $this->getMockForAbstractClass('Guzzle\Common\AbstractHasDispatcher');
23  $this->assertSame($mock, $mock->setEventDispatcher($d));
24  $this->assertSame($d, $mock->getEventDispatcher());
25  }
26 
28  {
29  $mock = $this->getMockForAbstractClass('Guzzle\Common\AbstractHasDispatcher');
30  $this->assertInstanceOf('Symfony\Component\EventDispatcher\EventDispatcher', $mock->getEventDispatcher());
31  }
32 
33  public function testHelperDispatchesEvents()
34  {
35  $data = array();
36  $mock = $this->getMockForAbstractClass('Guzzle\Common\AbstractHasDispatcher');
37  $mock->getEventDispatcher()->addListener('test', function(Event $e) use (&$data) {
38  $data = $e->getIterator()->getArrayCopy();
39  });
40  $mock->dispatch('test', array(
41  'param' => 'abc'
42  ));
43  $this->assertEquals(array(
44  'param' => 'abc',
45  ), $data);
46  }
47 
49  {
50  $mock = $this->getMockForAbstractClass('Guzzle\Common\AbstractHasDispatcher');
51  $subscriber = $this->getMockForAbstractClass('Symfony\Component\EventDispatcher\EventSubscriberInterface');
52 
53  $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
54  ->setMethods(array('addSubscriber'))
55  ->getMock();
56 
57  $dispatcher->expects($this->once())
58  ->method('addSubscriber');
59 
60  $mock->setEventDispatcher($dispatcher);
61  $mock->addSubscriber($subscriber);
62  }
63 }
Guzzle\Tests\Common\AbstractHasAdapterTest\testDoesNotRequireRegisteredEvents
testDoesNotRequireRegisteredEvents()
Definition: AbstractHasDispatcherTest.php:14
Guzzle\Tests\Common\AbstractHasAdapterTest\testHelperAttachesSubscribers
testHelperAttachesSubscribers()
Definition: AbstractHasDispatcherTest.php:48
Guzzle\Tests\GuzzleTestCase
Definition: GuzzleTestCase.php:22
Guzzle\Tests\Common\AbstractHasAdapterTest\testAllowsDispatcherToBeInjected
testAllowsDispatcherToBeInjected()
Definition: AbstractHasDispatcherTest.php:19
Guzzle\Common\Event
Definition: lib/vendor/guzzle/guzzle/src/Guzzle/Common/Event.php:10
Guzzle\Tests\Common\AbstractHasAdapterTest\testCreatesDefaultEventDispatcherIfNeeded
testCreatesDefaultEventDispatcherIfNeeded()
Definition: AbstractHasDispatcherTest.php:27
Guzzle\Tests\Common
Guzzle\Tests\Common\AbstractHasAdapterTest
Definition: AbstractHasDispatcherTest.php:12
Guzzle\Common\Event\getIterator
getIterator()
Definition: lib/vendor/guzzle/guzzle/src/Guzzle/Common/Event.php:26
Guzzle\Common\AbstractHasDispatcher
Definition: AbstractHasDispatcher.php:12
Symfony\Component\EventDispatcher\EventDispatcher
Definition: lib/vendor/symfony/event-dispatcher/EventDispatcher.php:28
Guzzle\Tests\Common\AbstractHasAdapterTest\testHelperDispatchesEvents
testHelperDispatchesEvents()
Definition: AbstractHasDispatcherTest.php:33
Guzzle\Common\AbstractHasDispatcher\getAllEvents
static getAllEvents()
Definition: AbstractHasDispatcher.php:20