Skip to content

Commit 3188265

Browse files
author
Chris Boulton
committed
Merge pull request chrisboulton#52 from ebernhardson/fix-stopListening
Resque_Event::stopListening does not remove the listener
2 parents a58820e + 010384b commit 3188265

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

lib/Resque/Event.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static function stopListening($event, $callback)
7373

7474
$key = array_search($callback, self::$events[$event]);
7575
if ($key !== false) {
76-
unset(self::$events[$key]);
76+
unset(self::$events[$event][$key]);
7777
}
7878

7979
return true;
@@ -86,4 +86,4 @@ public static function clearListeners()
8686
{
8787
self::$events = array();
8888
}
89-
}
89+
}

test/Resque/Tests/EventTest.php

+19-1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,24 @@ public function testAfterEnqueueEventCallbackFires()
101101
));
102102
$this->assertContains($callback, $this->callbacksHit, $event . ' callback (' . $callback .') was not called');
103103
}
104+
105+
public function testStopListeningRemovesListener()
106+
{
107+
$callback = 'beforePerformEventCallback';
108+
$event = 'beforePerform';
109+
110+
Resque_Event::listen($event, array($this, $callback));
111+
Resque_Event::stopListening($event, array($this, $callback));
112+
113+
$job = $this->getEventTestJob();
114+
$this->worker->perform($job);
115+
$this->worker->work(0);
116+
117+
$this->assertNotContains($callback, $this->callbacksHit,
118+
$event . ' callback (' . $callback .') was called though Resque_Event::stopListening was called'
119+
);
120+
}
121+
104122

105123
public function beforePerformEventDontPerformCallback($instance)
106124
{
@@ -146,4 +164,4 @@ public function afterForkEventCallback($job)
146164
{
147165
$this->assertValidEventCallback(__FUNCTION__, $job);
148166
}
149-
}
167+
}

0 commit comments

Comments
 (0)