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