Skip to content

Commit

Permalink
[EventDispatcher] Fix removeSubscriber() to work with priority syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
jmikola committed Aug 23, 2011
1 parent 0c6f47f commit 39fabab
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Symfony/Component/EventDispatcher/EventDispatcher.php
Expand Up @@ -127,8 +127,8 @@ public function addSubscriber(EventSubscriberInterface $subscriber)
*/
public function removeSubscriber(EventSubscriberInterface $subscriber)
{
foreach ($subscriber->getSubscribedEvents() as $eventName => $method) {
$this->removeListener($eventName, array($subscriber, $method));
foreach ($subscriber->getSubscribedEvents() as $eventName => $params) {
$this->removeListener($eventName, array($subscriber, is_string($params) ? $params : $params[0]));
}
}

Expand Down
Expand Up @@ -198,6 +198,15 @@ public function testRemoveSubscriber()
$this->assertFalse($this->dispatcher->hasListeners(self::preFoo));
$this->assertFalse($this->dispatcher->hasListeners(self::postFoo));
}

public function testRemoveSubscriberWithPriorities()
{
$eventSubscriber = new TestEventSubscriberWithPriorities();
$this->dispatcher->addSubscriber($eventSubscriber);
$this->assertTrue($this->dispatcher->hasListeners(self::preFoo));
$this->dispatcher->removeSubscriber($eventSubscriber);
$this->assertFalse($this->dispatcher->hasListeners(self::preFoo));
}
}

class TestEventListener
Expand Down

0 comments on commit 39fabab

Please sign in to comment.