File tree 2 files changed +21
-3
lines changed
2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -73,7 +73,7 @@ public static function stopListening($event, $callback)
73
73
74
74
$ key = array_search ($ callback , self ::$ events [$ event ]);
75
75
if ($ key !== false ) {
76
- unset(self ::$ events [$ key ]);
76
+ unset(self ::$ events [$ event ][ $ key ]);
77
77
}
78
78
79
79
return true ;
@@ -86,4 +86,4 @@ public static function clearListeners()
86
86
{
87
87
self ::$ events = array ();
88
88
}
89
- }
89
+ }
Original file line number Diff line number Diff line change @@ -101,6 +101,24 @@ public function testAfterEnqueueEventCallbackFires()
101
101
));
102
102
$ this ->assertContains ($ callback , $ this ->callbacksHit , $ event . ' callback ( ' . $ callback .') was not called ' );
103
103
}
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
+
104
122
105
123
public function beforePerformEventDontPerformCallback ($ instance )
106
124
{
@@ -146,4 +164,4 @@ public function afterForkEventCallback($job)
146
164
{
147
165
$ this ->assertValidEventCallback (__FUNCTION__ , $ job );
148
166
}
149
- }
167
+ }
You can’t perform that action at this time.
0 commit comments