4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\EventDispatcher\Tests
;
14 use Symfony\Component\EventDispatcher\Event
;
15 use Symfony\Component\EventDispatcher\ImmutableEventDispatcher
;
16 use Symfony\Component\EventDispatcher\EventSubscriberInterface
;
19 * @author Bernhard Schussek <bschussek@gmail.com>
21 class ImmutableEventDispatcherTest
extends \PHPUnit_Framework_TestCase
24 * @var \PHPUnit_Framework_MockObject_MockObject
26 private $innerDispatcher;
29 * @var ImmutableEventDispatcher
33 protected function setUp()
35 $this->innerDispatcher
= $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
36 $this->dispatcher
= new ImmutableEventDispatcher($this->innerDispatcher
);
39 public function testDispatchDelegates()
43 $this->innerDispatcher
->expects($this->once())
45 ->with('event', $event)
46 ->will($this->returnValue('result'));
48 $this->assertSame('result', $this->dispatcher
->dispatch('event', $event));
51 public function testGetListenersDelegates()
53 $this->innerDispatcher
->expects($this->once())
54 ->method('getListeners')
56 ->will($this->returnValue('result'));
58 $this->assertSame('result', $this->dispatcher
->getListeners('event'));
61 public function testHasListenersDelegates()
63 $this->innerDispatcher
->expects($this->once())
64 ->method('hasListeners')
66 ->will($this->returnValue('result'));
68 $this->assertSame('result', $this->dispatcher
->hasListeners('event'));
72 * @expectedException \BadMethodCallException
74 public function testAddListenerDisallowed()
76 $this->dispatcher
->addListener('event', function () { return 'foo'; });
80 * @expectedException \BadMethodCallException
82 public function testAddSubscriberDisallowed()
84 $subscriber = $this->getMock('Symfony\Component\EventDispatcher\EventSubscriberInterface');
86 $this->dispatcher
->addSubscriber($subscriber);
90 * @expectedException \BadMethodCallException
92 public function testRemoveListenerDisallowed()
94 $this->dispatcher
->removeListener('event', function () { return 'foo'; });
98 * @expectedException \BadMethodCallException
100 public function testRemoveSubscriberDisallowed()
102 $subscriber = $this->getMock('Symfony\Component\EventDispatcher\EventSubscriberInterface');
104 $this->dispatcher
->removeSubscriber($subscriber);