Skip to content

Commit

Permalink
Added a test for (and made corrections to) invalid callback exception.
Browse files Browse the repository at this point in the history
  • Loading branch information
boenrobot committed Feb 3, 2012
1 parent f5c86e0 commit 81e22ca
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/PEAR2/Net/RouterOS/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
16 changes: 16 additions & 0 deletions tests/ClientFeaturesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 81e22ca

Please sign in to comment.