From fab92ef114d43e1e54711b1b0ef16e7d20e2605b Mon Sep 17 00:00:00 2001 From: ebernhardson Date: Tue, 3 Apr 2012 15:23:25 -0700 Subject: [PATCH 1/2] fix bug preventing stopListening from working --- lib/Resque/Event.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Resque/Event.php b/lib/Resque/Event.php index 2264ae2..930c067 100644 --- a/lib/Resque/Event.php +++ b/lib/Resque/Event.php @@ -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; @@ -86,4 +86,4 @@ class Resque_Event { self::$events = array(); } -} \ No newline at end of file +} From 010384b2965970366ea9ca1c9b87046d4bf25e40 Mon Sep 17 00:00:00 2001 From: ebernhardson Date: Wed, 4 Apr 2012 18:27:08 -0700 Subject: [PATCH 2/2] unit test to verify fix of Resque_Event::stopListening --- test/Resque/Tests/EventTest.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/test/Resque/Tests/EventTest.php b/test/Resque/Tests/EventTest.php index 3d2a536..0bf5ee9 100644 --- a/test/Resque/Tests/EventTest.php +++ b/test/Resque/Tests/EventTest.php @@ -101,6 +101,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) { @@ -146,4 +164,4 @@ class Resque_Tests_EventTest extends Resque_Tests_TestCase { $this->assertValidEventCallback(__FUNCTION__, $job); } -} \ No newline at end of file +}