Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 /*
|
Chris@0
|
4 * This file is part of the Symfony package.
|
Chris@0
|
5 *
|
Chris@0
|
6 * (c) Fabien Potencier <fabien@symfony.com>
|
Chris@0
|
7 *
|
Chris@0
|
8 * For the full copyright and license information, please view the LICENSE
|
Chris@0
|
9 * file that was distributed with this source code.
|
Chris@0
|
10 */
|
Chris@0
|
11
|
Chris@0
|
12 namespace Symfony\Component\EventDispatcher\Tests;
|
Chris@0
|
13
|
Chris@0
|
14 use PHPUnit\Framework\TestCase;
|
Chris@0
|
15 use Symfony\Component\EventDispatcher\Event;
|
Chris@0
|
16 use Symfony\Component\EventDispatcher\ImmutableEventDispatcher;
|
Chris@0
|
17
|
Chris@0
|
18 /**
|
Chris@0
|
19 * @author Bernhard Schussek <bschussek@gmail.com>
|
Chris@0
|
20 */
|
Chris@0
|
21 class ImmutableEventDispatcherTest extends TestCase
|
Chris@0
|
22 {
|
Chris@0
|
23 /**
|
Chris@0
|
24 * @var \PHPUnit_Framework_MockObject_MockObject
|
Chris@0
|
25 */
|
Chris@0
|
26 private $innerDispatcher;
|
Chris@0
|
27
|
Chris@0
|
28 /**
|
Chris@0
|
29 * @var ImmutableEventDispatcher
|
Chris@0
|
30 */
|
Chris@0
|
31 private $dispatcher;
|
Chris@0
|
32
|
Chris@0
|
33 protected function setUp()
|
Chris@0
|
34 {
|
Chris@0
|
35 $this->innerDispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock();
|
Chris@0
|
36 $this->dispatcher = new ImmutableEventDispatcher($this->innerDispatcher);
|
Chris@0
|
37 }
|
Chris@0
|
38
|
Chris@0
|
39 public function testDispatchDelegates()
|
Chris@0
|
40 {
|
Chris@0
|
41 $event = new Event();
|
Chris@0
|
42
|
Chris@0
|
43 $this->innerDispatcher->expects($this->once())
|
Chris@0
|
44 ->method('dispatch')
|
Chris@0
|
45 ->with('event', $event)
|
Chris@0
|
46 ->will($this->returnValue('result'));
|
Chris@0
|
47
|
Chris@0
|
48 $this->assertSame('result', $this->dispatcher->dispatch('event', $event));
|
Chris@0
|
49 }
|
Chris@0
|
50
|
Chris@0
|
51 public function testGetListenersDelegates()
|
Chris@0
|
52 {
|
Chris@0
|
53 $this->innerDispatcher->expects($this->once())
|
Chris@0
|
54 ->method('getListeners')
|
Chris@0
|
55 ->with('event')
|
Chris@0
|
56 ->will($this->returnValue('result'));
|
Chris@0
|
57
|
Chris@0
|
58 $this->assertSame('result', $this->dispatcher->getListeners('event'));
|
Chris@0
|
59 }
|
Chris@0
|
60
|
Chris@0
|
61 public function testHasListenersDelegates()
|
Chris@0
|
62 {
|
Chris@0
|
63 $this->innerDispatcher->expects($this->once())
|
Chris@0
|
64 ->method('hasListeners')
|
Chris@0
|
65 ->with('event')
|
Chris@0
|
66 ->will($this->returnValue('result'));
|
Chris@0
|
67
|
Chris@0
|
68 $this->assertSame('result', $this->dispatcher->hasListeners('event'));
|
Chris@0
|
69 }
|
Chris@0
|
70
|
Chris@0
|
71 /**
|
Chris@0
|
72 * @expectedException \BadMethodCallException
|
Chris@0
|
73 */
|
Chris@0
|
74 public function testAddListenerDisallowed()
|
Chris@0
|
75 {
|
Chris@0
|
76 $this->dispatcher->addListener('event', function () { return 'foo'; });
|
Chris@0
|
77 }
|
Chris@0
|
78
|
Chris@0
|
79 /**
|
Chris@0
|
80 * @expectedException \BadMethodCallException
|
Chris@0
|
81 */
|
Chris@0
|
82 public function testAddSubscriberDisallowed()
|
Chris@0
|
83 {
|
Chris@0
|
84 $subscriber = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventSubscriberInterface')->getMock();
|
Chris@0
|
85
|
Chris@0
|
86 $this->dispatcher->addSubscriber($subscriber);
|
Chris@0
|
87 }
|
Chris@0
|
88
|
Chris@0
|
89 /**
|
Chris@0
|
90 * @expectedException \BadMethodCallException
|
Chris@0
|
91 */
|
Chris@0
|
92 public function testRemoveListenerDisallowed()
|
Chris@0
|
93 {
|
Chris@0
|
94 $this->dispatcher->removeListener('event', function () { return 'foo'; });
|
Chris@0
|
95 }
|
Chris@0
|
96
|
Chris@0
|
97 /**
|
Chris@0
|
98 * @expectedException \BadMethodCallException
|
Chris@0
|
99 */
|
Chris@0
|
100 public function testRemoveSubscriberDisallowed()
|
Chris@0
|
101 {
|
Chris@0
|
102 $subscriber = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventSubscriberInterface')->getMock();
|
Chris@0
|
103
|
Chris@0
|
104 $this->dispatcher->removeSubscriber($subscriber);
|
Chris@0
|
105 }
|
Chris@0
|
106 }
|