bug #18388 [EventDispatcher] check for method to exist (xabbuh)
This PR was merged into the 2.8 branch.
Discussion
----------
[EventDispatcher] check for method to exist
| Q | A
| ------------- | ---
| Branch? | 2.8
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | https://github.com/symfony/symfony/pull/16301#issuecomment-193150055
| License | MIT
| Doc PR |
This change must be reverted after being merged into the `3.0` branch (the `getListenerPriority()` method was added to the interface in Symfony 3.0).
Commits
-------
78ae2ad
[EventDispatcher] check for method to exist
This commit is contained in:
commit
27c122e0ca
@ -104,6 +104,10 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
|
|||||||
*/
|
*/
|
||||||
public function getListenerPriority($eventName, $listener)
|
public function getListenerPriority($eventName, $listener)
|
||||||
{
|
{
|
||||||
|
if (!method_exists($this->dispatcher, 'getListenerPriority')) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return $this->dispatcher->getListenerPriority($eventName, $listener);
|
return $this->dispatcher->getListenerPriority($eventName, $listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,6 +73,16 @@ class TraceableEventDispatcherTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertSame(123, $tdispatcher->getListenerPriority('foo', $listeners[0]));
|
$this->assertSame(123, $tdispatcher->getListenerPriority('foo', $listeners[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetListenerPriorityReturnsZeroWhenWrappedMethodDoesNotExist()
|
||||||
|
{
|
||||||
|
$dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
|
||||||
|
$traceableEventDispatcher = new TraceableEventDispatcher($dispatcher, new Stopwatch());
|
||||||
|
$traceableEventDispatcher->addListener('foo', function () {}, 123);
|
||||||
|
$listeners = $traceableEventDispatcher->getListeners('foo');
|
||||||
|
|
||||||
|
$this->assertSame(0, $traceableEventDispatcher->getListenerPriority('foo', $listeners[0]));
|
||||||
|
}
|
||||||
|
|
||||||
public function testAddRemoveSubscriber()
|
public function testAddRemoveSubscriber()
|
||||||
{
|
{
|
||||||
$dispatcher = new EventDispatcher();
|
$dispatcher = new EventDispatcher();
|
||||||
|
Reference in New Issue
Block a user