-
Notifications
You must be signed in to change notification settings - Fork 175
/
publish.phpt
134 lines (115 loc) · 3.43 KB
/
publish.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
--TEST--
Mosquitto\Client::publish()
--SKIPIF--
if (!extension_loaded('mosquitto')) die('skip - Mosquitto extension not available');
--FILE--
<?php
include(dirname(__DIR__) . '/setup.php');
$client = new Mosquitto\Client();
try {
$client->publish();
echo "Done\n";
} catch (Mosquitto\Exception $e) {
writeException($e);
}
try {
$client->publish(new stdClass);
echo "Done\n";
} catch (Mosquitto\Exception $e) {
writeException($e);
}
try {
$client->publish(new stdClass, new stdClass);
echo "Done\n";
} catch (Mosquitto\Exception $e) {
writeException($e);
}
try {
$client->publish('#');
echo "Done\n";
} catch (Mosquitto\Exception $e) {
writeException($e);
}
try {
$client->publish('topic');
echo "Done\n";
} catch (Mosquitto\Exception $e) {
writeException($e);
}
try {
$client->publish('topic', 'payload', new stdClass);
echo "Done\n";
} catch (Mosquitto\Exception $e) {
writeException($e);
}
try {
$client->publish('topic', 'payload', 1, new stdClass);
echo "Done\n";
} catch (Mosquitto\Exception $e) {
writeException($e);
}
try {
$client->publish('topic', 'payload', 1);
echo "Done\n";
} catch (Mosquitto\Exception $e) {
writeException($e);
}
try {
$client->publish('topic', 'payload', 1, true);
echo "Done\n";
} catch (Mosquitto\Exception $e) {
writeException($e);
}
try {
$client->publish('topic', 'payload', 1, false);
echo "Done\n";
} catch (Mosquitto\Exception $e) {
writeException($e);
}
try {
$client->publish('topic', 'payload');
echo "Done\n";
} catch (Mosquitto\Exception $e) {
writeException($e);
}
$client2 = new Mosquitto\Client();
$looping = true;
$client2->onConnect(function() use ($client2) {
$client2->subscribe('publish', 0);
$client2->publish('publish', 'hello', 0);
});
$client2->onMessage(function($m) use ($client2, &$looping) {
var_dump($m);
$client2->disconnect();
$looping = false;
});
$client2->connect(TEST_MQTT_HOST);
for ($i = 0; $i < 10; $i++) {
if (!$looping) break;
$client2->loop(50);
}
?>
--EXPECTF--
Caught Mosquitto\Exception with code 0 and message: Mosquitto\Client::publish() expects at least 2 parameters, 0 given
Caught Mosquitto\Exception with code 0 and message: Mosquitto\Client::publish() expects at least 2 parameters, 1 given
Caught Mosquitto\Exception with code 0 and message: Mosquitto\Client::publish() expects parameter 1 to be string, object given
Caught Mosquitto\Exception with code 0 and message: Mosquitto\Client::publish() expects at least 2 parameters, 1 given
Caught Mosquitto\Exception with code 0 and message: Mosquitto\Client::publish() expects at least 2 parameters, 1 given
Caught Mosquitto\Exception with code 0 and message: Mosquitto\Client::publish() expects parameter 3 to be %s, object given
Caught Mosquitto\Exception with code 0 and message: Mosquitto\Client::publish() expects parameter 4 to be boolean, object given
Caught Mosquitto\Exception with code 0 and message: The client is not currently connected.
Caught Mosquitto\Exception with code 0 and message: The client is not currently connected.
Caught Mosquitto\Exception with code 0 and message: The client is not currently connected.
Caught Mosquitto\Exception with code 0 and message: The client is not currently connected.
object(Mosquitto\Message)#%d (5) {
["mid"]=>
int(%d)
["topic"]=>
string(7) "publish"
["payload"]=>
string(5) "hello"
["qos"]=>
int(0)
["retain"]=>
bool(false)
}