-
Notifications
You must be signed in to change notification settings - Fork 147
/
Copy pathonDisconnect.phpt
54 lines (44 loc) · 1.35 KB
/
onDisconnect.phpt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
--TEST--
Mosquitto\Client::onDisconnect()
--SKIPIF--
if (!extension_loaded('mosquitto')) die('skip - Mosquitto extension not available');
--FILE--
<?php
include(dirname(__DIR__) . '/setup.php');
try {
$client = new Mosquitto\Client;
$client->onDisconnect('foo');
} catch (Exception $e) {
printf("Caught %s with code %d and message: %s\n", get_class($e), $e->getCode(), $e->getMessage());
}
unset($client);
$client = new Mosquitto\Client;
$client->onConnect(function() use ($client) {
echo "Triggering disconnect\n";
$client->disconnect();
});
$client->onDisconnect(function() {
echo "Disconnected\n";
});
$client->connect(TEST_MQTT_HOST);
$client->loopForever(50);
unset($client);
/* onDisconnect called when Client is destroyed */
$client = new Mosquitto\Client;
$loop = true;
$client->onDisconnect(function() use (&$loop) {
$loop = false;
echo "Disconnected\n";
});
$client->connect(TEST_MQTT_HOST);
for ($i = 0; $i < 5; $i++) {
if (!$loop) break;
$client->loop(50);
}
?>
--EXPECTF--
Caught error 4096 (Argument 1 passed to Mosquitto\Client::onDisconnect() must be callable, string given) in %s on line 6
Caught Mosquitto\Exception with code 0 and message: Mosquitto\Client::onDisconnect() expects parameter 1 to be a valid callback, function 'foo' not found or invalid function name
Triggering disconnect
Disconnected
Disconnected