Merge pull request #52 from ebernhardson/fix-stopListening

Resque_Event::stopListening does not remove the listener
This commit is contained in:
Chris Boulton 2012-05-03 21:00:18 -07:00
commit 3188265655
2 changed files with 21 additions and 3 deletions

View File

@ -73,7 +73,7 @@ class Resque_Event
$key = array_search($callback, self::$events[$event]);
if ($key !== false) {
unset(self::$events[$key]);
unset(self::$events[$event][$key]);
}
return true;

View File

@ -102,6 +102,24 @@ class Resque_Tests_EventTest extends Resque_Tests_TestCase
$this->assertContains($callback, $this->callbacksHit, $event . ' callback (' . $callback .') was not called');
}
public function testStopListeningRemovesListener()
{
$callback = 'beforePerformEventCallback';
$event = 'beforePerform';
Resque_Event::listen($event, array($this, $callback));
Resque_Event::stopListening($event, array($this, $callback));
$job = $this->getEventTestJob();
$this->worker->perform($job);
$this->worker->work(0);
$this->assertNotContains($callback, $this->callbacksHit,
$event . ' callback (' . $callback .') was called though Resque_Event::stopListening was called'
);
}
public function beforePerformEventDontPerformCallback($instance)
{
$this->callbacksHit[] = __FUNCTION__;