Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

  • Loading branch information...
commit 81e22cae9e8734561e6d3f3f12556ca1a05b7788 1 parent f5c86e0
@boenrobot boenrobot authored
Showing with 22 additions and 5 deletions.
  1. +6 −5 src/PEAR2/Net/RouterOS/Client.php
  2. +16 −0 tests/ClientFeaturesTest.php
View
11 src/PEAR2/Net/RouterOS/Client.php
@@ -264,19 +264,20 @@ public function sendAsync(Request $request, $callback = null)
10501
);
}
+ if (null !== $callback && !is_callable($callback, true)) {
+ throw new UnexpectedValueException(
+ 'Invalid callback provided.', 10502
+ );
+ }
$this->send($request);
if (null === $callback) {
//Register the request at the buffer
$this->responseBuffer[$tag] = array();
- } elseif (is_callable($callback, true)) {
+ } else {
//Prepare the callback
$this->callbacks[$tag] = $callback;
- } else {
- throw new UnexpectedValueException(
- 'Invalid callback provided.', 10502
- );
}
return $this;
}
View
16 tests/ClientFeaturesTest.php
@@ -135,6 +135,22 @@ public function testSendAsyncUniqueTagRequirement()
}
}
+ public function testSendAsyncValidCallbackRequirement()
+ {
+ $ping = new Request('/ping');
+ $ping->setArgument('address', HOSTNAME_INVALID);
+ $ping->setTag('ping');
+ try {
+ $this->object->sendAsync($ping, 3);
+
+ $this->fail('The call had to fail.');
+ } catch (UnexpectedValueException $e) {
+ $this->assertEquals(
+ 10502, $e->getCode(), 'Improper exception code.'
+ );
+ }
+ }
+
public function testSendAsyncWithCallbackAndTempLoop()
{
$ping = new Request('/ping');
Please sign in to comment.
Something went wrong with that request. Please try again.