Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\EventDispatcher\Tests; Chris@0: Chris@0: use PHPUnit\Framework\TestCase; Chris@0: use Symfony\Component\EventDispatcher\Event; Chris@0: use Symfony\Component\EventDispatcher\ImmutableEventDispatcher; Chris@0: Chris@0: /** Chris@0: * @author Bernhard Schussek Chris@0: */ Chris@0: class ImmutableEventDispatcherTest extends TestCase Chris@0: { Chris@0: /** Chris@0: * @var \PHPUnit_Framework_MockObject_MockObject Chris@0: */ Chris@0: private $innerDispatcher; Chris@0: Chris@0: /** Chris@0: * @var ImmutableEventDispatcher Chris@0: */ Chris@0: private $dispatcher; Chris@0: Chris@0: protected function setUp() Chris@0: { Chris@0: $this->innerDispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock(); Chris@0: $this->dispatcher = new ImmutableEventDispatcher($this->innerDispatcher); Chris@0: } Chris@0: Chris@0: public function testDispatchDelegates() Chris@0: { Chris@0: $event = new Event(); Chris@0: Chris@0: $this->innerDispatcher->expects($this->once()) Chris@0: ->method('dispatch') Chris@0: ->with('event', $event) Chris@0: ->will($this->returnValue('result')); Chris@0: Chris@0: $this->assertSame('result', $this->dispatcher->dispatch('event', $event)); Chris@0: } Chris@0: Chris@0: public function testGetListenersDelegates() Chris@0: { Chris@0: $this->innerDispatcher->expects($this->once()) Chris@0: ->method('getListeners') Chris@0: ->with('event') Chris@0: ->will($this->returnValue('result')); Chris@0: Chris@0: $this->assertSame('result', $this->dispatcher->getListeners('event')); Chris@0: } Chris@0: Chris@0: public function testHasListenersDelegates() Chris@0: { Chris@0: $this->innerDispatcher->expects($this->once()) Chris@0: ->method('hasListeners') Chris@0: ->with('event') Chris@0: ->will($this->returnValue('result')); Chris@0: Chris@0: $this->assertSame('result', $this->dispatcher->hasListeners('event')); Chris@0: } Chris@0: Chris@0: /** Chris@0: * @expectedException \BadMethodCallException Chris@0: */ Chris@0: public function testAddListenerDisallowed() Chris@0: { Chris@0: $this->dispatcher->addListener('event', function () { return 'foo'; }); Chris@0: } Chris@0: Chris@0: /** Chris@0: * @expectedException \BadMethodCallException Chris@0: */ Chris@0: public function testAddSubscriberDisallowed() Chris@0: { Chris@0: $subscriber = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventSubscriberInterface')->getMock(); Chris@0: Chris@0: $this->dispatcher->addSubscriber($subscriber); Chris@0: } Chris@0: Chris@0: /** Chris@0: * @expectedException \BadMethodCallException Chris@0: */ Chris@0: public function testRemoveListenerDisallowed() Chris@0: { Chris@0: $this->dispatcher->removeListener('event', function () { return 'foo'; }); Chris@0: } Chris@0: Chris@0: /** Chris@0: * @expectedException \BadMethodCallException Chris@0: */ Chris@0: public function testRemoveSubscriberDisallowed() Chris@0: { Chris@0: $subscriber = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventSubscriberInterface')->getMock(); Chris@0: Chris@0: $this->dispatcher->removeSubscriber($subscriber); Chris@0: } Chris@0: }