File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -130,8 +130,9 @@ private function dequeueEvent(){
130130 */
131131 private function determineType (callable $ callable ){
132132 $ reflector = $ this ->reflect ($ callable );
133- if ($ reflector ->getNumberOfParameters () != 1 ) throw new \InvalidArgumentException ("Observers must ONLY accept 1 parameter. " );
134- $ type = $ reflector ->getParameters ()[0 ]->getClass ();
133+ if ($ reflector ->getNumberOfParameters () > 1 ) throw new \InvalidArgumentException ("Observers must ONLY accept 1 parameter. " );
134+ $ reflectionParameters = $ reflector ->getParameters ();
135+ $ type = count ($ reflectionParameters )?$ reflectionParameters [0 ]->getClass ():null ;
135136 return $ type ?$ type ->getName ():null ;
136137 }
137138
Original file line number Diff line number Diff line change @@ -114,6 +114,16 @@ public function testObserverRemoval(){
114114
115115 }
116116
117+ public function testAllowsZeroArgumentsObservers (){
118+ $ func = function ()use (&$ happened ){
119+ $ happened = true ;
120+ };
121+ $ this ->addObserver ($ func );
122+
123+ $ this ->notifyObservers (1 );
124+ $ this ->assertThat ($ happened , $ this ->isTrue ());
125+ }
126+
117127
118128 public function verifyEvent ($ event ){
119129 $ this ->assertThat (count ($ this ->events ), $ this ->equalTo (1 ));
You can’t perform that action at this time.
0 commit comments