Skip to content
This repository
Browse code

Added a test for (and made corrections to) invalid callback exception.

  • Loading branch information...
commit 81e22cae9e8734561e6d3f3f12556ca1a05b7788 1 parent f5c86e0
Vasil Rangelov authored February 04, 2012
11  src/PEAR2/Net/RouterOS/Client.php
@@ -264,19 +264,20 @@ public function sendAsync(Request $request, $callback = null)
264 264
                 10501
265 265
             );
266 266
         }
  267
+        if (null !== $callback && !is_callable($callback, true)) {
  268
+            throw new UnexpectedValueException(
  269
+                'Invalid callback provided.', 10502
  270
+            );
  271
+        }
267 272
         
268 273
         $this->send($request);
269 274
 
270 275
         if (null === $callback) {
271 276
             //Register the request at the buffer
272 277
             $this->responseBuffer[$tag] = array();
273  
-        } elseif (is_callable($callback, true)) {
  278
+        } else {
274 279
             //Prepare the callback
275 280
             $this->callbacks[$tag] = $callback;
276  
-        } else {
277  
-            throw new UnexpectedValueException(
278  
-                'Invalid callback provided.', 10502
279  
-            );
280 281
         }
281 282
         return $this;
282 283
     }
16  tests/ClientFeaturesTest.php
@@ -135,6 +135,22 @@ public function testSendAsyncUniqueTagRequirement()
135 135
         }
136 136
     }
137 137
 
  138
+    public function testSendAsyncValidCallbackRequirement()
  139
+    {
  140
+        $ping = new Request('/ping');
  141
+        $ping->setArgument('address', HOSTNAME_INVALID);
  142
+        $ping->setTag('ping');
  143
+        try {
  144
+            $this->object->sendAsync($ping, 3);
  145
+
  146
+            $this->fail('The call had to fail.');
  147
+        } catch (UnexpectedValueException $e) {
  148
+            $this->assertEquals(
  149
+                10502, $e->getCode(), 'Improper exception code.'
  150
+            );
  151
+        }
  152
+    }
  153
+
138 154
     public function testSendAsyncWithCallbackAndTempLoop()
139 155
     {
140 156
         $ping = new Request('/ping');

0 notes on commit 81e22ca

Please sign in to comment.
Something went wrong with that request. Please try again.