diff --git a/src/Jmikola/WildcardEventDispatcher/WildcardEventDispatcher.php b/src/Jmikola/WildcardEventDispatcher/WildcardEventDispatcher.php index b32ffb6..9c525be 100644 --- a/src/Jmikola/WildcardEventDispatcher/WildcardEventDispatcher.php +++ b/src/Jmikola/WildcardEventDispatcher/WildcardEventDispatcher.php @@ -198,9 +198,19 @@ class WildcardEventDispatcher implements EventDispatcherInterface /** * @see EventDispatcherInterface::getListenerPriority() + * @throws \InvalidArgumentException if $eventName contains a wildcard pattern + * @throws \BadMethodCallException if this method is not implemented on the composed EventDispatcher */ public function getListenerPriority($eventName, $listener) { + if ($this->hasWildcards($eventName)) { + throw new \InvalidArgumentException('Wildcard patterns are not supported'); + } + + if ( ! method_exists($this->dispatcher, 'getListenerPriority')) { + throw new \BadMethodCallException('getListenerPriority() is not implemented'); + } + return $this->dispatcher->getListenerPriority($eventName, $listener); } } diff --git a/tests/Jmikola/Tests/WildcardEventDispatcher/WildcardEventDispatcherTest.php b/tests/Jmikola/Tests/WildcardEventDispatcher/WildcardEventDispatcherTest.php index c8076e6..20353b4 100644 --- a/tests/Jmikola/Tests/WildcardEventDispatcher/WildcardEventDispatcherTest.php +++ b/tests/Jmikola/Tests/WildcardEventDispatcher/WildcardEventDispatcherTest.php @@ -146,6 +146,40 @@ class EventDispatcherTest extends \PHPUnit_Framework_TestCase $this->dispatcher->removeSubscriber($subscriber); } + public function testGetListenerPriorityInvokesMethodOnInnerDispather() + { + if ( ! method_exists('Symfony\Component\EventDispatcher\EventDispatcherInterface', 'getListenerPriority')) { + $this->markTestSkipped('getListenerPriority() does not exist on EventDispatcherInterface'); + } + + $this->innerDispatcher->expects($this->once()) + ->method('getListenerPriority') + ->with('core.request', 'callback') + ->will($this->returnValue(1)); + + $this->assertSame(1, $this->dispatcher->getListenerPriority('core.request', 'callback')); + } + + /** + * @expectedException InvalidArgumentException + */ + public function testGetListenerPriorityRequiresEventNameWithoutWildcards() + { + $this->dispatcher->getListenerPriority('core.*', 'callback'); + } + + /** + * @expectedException BadMethodCallException + */ + public function testGetListenerPriorityRequiresMethodOnInnerDispather() + { + if (method_exists('Symfony\Component\EventDispatcher\EventDispatcherInterface', 'getListenerPriority')) { + $this->markTestSkipped('getListenerPriority() exists on EventDispatcherInterface'); + } + + $this->dispatcher->getListenerPriority('core.request', 'callback'); + } + private function getMockEventDispatcher() { return $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock();