1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace Symfony\Component\EventDispatcher\Tests;
13:
14: use Symfony\Component\EventDispatcher\Event;
15: use Symfony\Component\EventDispatcher\ImmutableEventDispatcher;
16:
17: 18: 19:
20: class ImmutableEventDispatcherTest extends \PHPUnit_Framework_TestCase
21: {
22: 23: 24:
25: private $innerDispatcher;
26:
27: 28: 29:
30: private $dispatcher;
31:
32: protected function setUp()
33: {
34: $this->innerDispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
35: $this->dispatcher = new ImmutableEventDispatcher($this->innerDispatcher);
36: }
37:
38: public function testDispatchDelegates()
39: {
40: $event = new Event();
41:
42: $this->innerDispatcher->expects($this->once())
43: ->method('dispatch')
44: ->with('event', $event)
45: ->will($this->returnValue('result'));
46:
47: $this->assertSame('result', $this->dispatcher->dispatch('event', $event));
48: }
49:
50: public function testGetListenersDelegates()
51: {
52: $this->innerDispatcher->expects($this->once())
53: ->method('getListeners')
54: ->with('event')
55: ->will($this->returnValue('result'));
56:
57: $this->assertSame('result', $this->dispatcher->getListeners('event'));
58: }
59:
60: public function testHasListenersDelegates()
61: {
62: $this->innerDispatcher->expects($this->once())
63: ->method('hasListeners')
64: ->with('event')
65: ->will($this->returnValue('result'));
66:
67: $this->assertSame('result', $this->dispatcher->hasListeners('event'));
68: }
69:
70: 71: 72:
73: public function testAddListenerDisallowed()
74: {
75: $this->dispatcher->addListener('event', function () { return 'foo'; });
76: }
77:
78: 79: 80:
81: public function testAddSubscriberDisallowed()
82: {
83: $subscriber = $this->getMock('Symfony\Component\EventDispatcher\EventSubscriberInterface');
84:
85: $this->dispatcher->addSubscriber($subscriber);
86: }
87:
88: 89: 90:
91: public function testRemoveListenerDisallowed()
92: {
93: $this->dispatcher->removeListener('event', function () { return 'foo'; });
94: }
95:
96: 97: 98:
99: public function testRemoveSubscriberDisallowed()
100: {
101: $subscriber = $this->getMock('Symfony\Component\EventDispatcher\EventSubscriberInterface');
102:
103: $this->dispatcher->removeSubscriber($subscriber);
104: }
105: }
106: