Skip to content

Commit 81e22ca

Browse files
committed
Added a test for (and made corrections to) invalid callback exception.
1 parent f5c86e0 commit 81e22ca

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/PEAR2/Net/RouterOS/Client.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,19 +264,20 @@ public function sendAsync(Request $request, $callback = null)
264264
10501
265265
);
266266
}
267+
if (null !== $callback && !is_callable($callback, true)) {
268+
throw new UnexpectedValueException(
269+
'Invalid callback provided.', 10502
270+
);
271+
}
267272

268273
$this->send($request);
269274

270275
if (null === $callback) {
271276
//Register the request at the buffer
272277
$this->responseBuffer[$tag] = array();
273-
} elseif (is_callable($callback, true)) {
278+
} else {
274279
//Prepare the callback
275280
$this->callbacks[$tag] = $callback;
276-
} else {
277-
throw new UnexpectedValueException(
278-
'Invalid callback provided.', 10502
279-
);
280281
}
281282
return $this;
282283
}

tests/ClientFeaturesTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,22 @@ public function testSendAsyncUniqueTagRequirement()
135135
}
136136
}
137137

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+
138154
public function testSendAsyncWithCallbackAndTempLoop()
139155
{
140156
$ping = new Request('/ping');

0 commit comments

Comments
 (0)