mirror of
https://github.com/stan220/WildcardEventDispatcher.git
synced 2026-09-08 16:28:35 +00:00
Throw exceptions for getListenerPriority() incompatibilities
For the time being, do not support wildcard patterns with getListenerPriority(). An exception will be thrown if getListenerPriority() is not implemented on the inner dispatcher. The method was added in https://github.com/symfony/symfony/pull/16198 for Symfony 2.8. It was added to the interface in Symfony 3.0, which is relevant for our test cases.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user