Open Journal Systems  3.3.0
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 
13 
14 use PHPUnit\Framework\TestCase;
17 
21 class ImmutableEventDispatcherTest extends TestCase
22 {
26  private $innerDispatcher;
27 
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 
74  public function testAddListenerDisallowed()
75  {
76  $this->dispatcher->addListener('event', function () { return 'foo'; });
77  }
78 
82  public function testAddSubscriberDisallowed()
83  {
84  $subscriber = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventSubscriberInterface')->getMock();
85 
86  $this->dispatcher->addSubscriber($subscriber);
87  }
88 
92  public function testRemoveListenerDisallowed()
93  {
94  $this->dispatcher->removeListener('event', function () { return 'foo'; });
95  }
96 
100  public function testRemoveSubscriberDisallowed()
101  {
102  $subscriber = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventSubscriberInterface')->getMock();
103 
104  $this->dispatcher->removeSubscriber($subscriber);
105  }
106 }
Symfony\Component\EventDispatcher\ImmutableEventDispatcher
Definition: lib/vendor/symfony/event-dispatcher/ImmutableEventDispatcher.php:19
Symfony\Component\EventDispatcher\Tests\ImmutableEventDispatcherTest\testDispatchDelegates
testDispatchDelegates()
Definition: vendor/symfony/event-dispatcher/Tests/ImmutableEventDispatcherTest.php:45
Symfony\Component\EventDispatcher\Tests\ImmutableEventDispatcherTest\testAddSubscriberDisallowed
testAddSubscriberDisallowed()
Definition: vendor/symfony/event-dispatcher/Tests/ImmutableEventDispatcherTest.php:88
Symfony\Component\EventDispatcher\Tests\ImmutableEventDispatcherTest\testRemoveListenerDisallowed
testRemoveListenerDisallowed()
Definition: vendor/symfony/event-dispatcher/Tests/ImmutableEventDispatcherTest.php:98
Symfony\Component\EventDispatcher\Tests\ImmutableEventDispatcherTest\testAddListenerDisallowed
testAddListenerDisallowed()
Definition: vendor/symfony/event-dispatcher/Tests/ImmutableEventDispatcherTest.php:80
Symfony\Component\EventDispatcher\Tests\ImmutableEventDispatcherTest\testHasListenersDelegates
testHasListenersDelegates()
Definition: vendor/symfony/event-dispatcher/Tests/ImmutableEventDispatcherTest.php:67
Symfony\Component\EventDispatcher\Tests\ImmutableEventDispatcherTest\testRemoveSubscriberDisallowed
testRemoveSubscriberDisallowed()
Definition: vendor/symfony/event-dispatcher/Tests/ImmutableEventDispatcherTest.php:106
Symfony\Component\EventDispatcher\Tests
Definition: lib/vendor/symfony/event-dispatcher/Tests/AbstractEventDispatcherTest.php:12
Symfony\Component\EventDispatcher\Event
Definition: lib/vendor/symfony/event-dispatcher/Event.php:28
Symfony\Component\EventDispatcher\Tests\ImmutableEventDispatcherTest\testGetListenersDelegates
testGetListenersDelegates()
Definition: vendor/symfony/event-dispatcher/Tests/ImmutableEventDispatcherTest.php:57
Symfony\Component\EventDispatcher\Tests\ImmutableEventDispatcherTest\setUp
setUp()
Definition: vendor/symfony/event-dispatcher/Tests/ImmutableEventDispatcherTest.php:39