77
88namespace Tests \Feature ;
99
10+ use PhpMqtt \Client \ConnectionSettings ;
1011use PhpMqtt \Client \MqttClient ;
1112use Tests \TestCase ;
1213
@@ -20,29 +21,40 @@ class PublishSubscribeTest extends TestCase
2021 public function publishSubscribeData (): array
2122 {
2223 return [
23- ['test/foo/bar/baz ' , 'test/foo/bar/baz ' , 'hello world ' , []],
24- ['test/foo/bar/+ ' , 'test/foo/bar/baz ' , 'hello world ' , ['baz ' ]],
25- ['test/foo/+/baz ' , 'test/foo/bar/baz ' , 'hello world ' , ['bar ' ]],
26- ['test/foo/# ' , 'test/foo/bar/baz ' , 'hello world ' , ['bar/baz ' ]],
27- ['test/foo/+/bar/# ' , 'test/foo/my/bar/baz ' , 'hello world ' , ['my ' , 'baz ' ]],
28- ['test/foo/+/bar/# ' , 'test/foo/my/bar/baz/blub ' , 'hello world ' , ['my ' , 'baz/blub ' ]],
29- ['test/foo/bar/baz ' , 'test/foo/bar/baz ' , random_bytes (2 * 1024 * 1024 ), []], // 2MB message
24+ [false , 'test/foo/bar/baz ' , 'test/foo/bar/baz ' , 'hello world ' , []],
25+ [false , 'test/foo/bar/+ ' , 'test/foo/bar/baz ' , 'hello world ' , ['baz ' ]],
26+ [false , 'test/foo/+/baz ' , 'test/foo/bar/baz ' , 'hello world ' , ['bar ' ]],
27+ [false , 'test/foo/# ' , 'test/foo/bar/baz ' , 'hello world ' , ['bar/baz ' ]],
28+ [false , 'test/foo/+/bar/# ' , 'test/foo/my/bar/baz ' , 'hello world ' , ['my ' , 'baz ' ]],
29+ [false , 'test/foo/+/bar/# ' , 'test/foo/my/bar/baz/blub ' , 'hello world ' , ['my ' , 'baz/blub ' ]],
30+ [false , 'test/foo/bar/baz ' , 'test/foo/bar/baz ' , random_bytes (2 * 1024 * 1024 ), []], // 2MB message
31+ [true , 'test/foo/bar/baz ' , 'test/foo/bar/baz ' , 'hello world ' , []],
32+ [true , 'test/foo/bar/+ ' , 'test/foo/bar/baz ' , 'hello world ' , ['baz ' ]],
33+ [true , 'test/foo/+/baz ' , 'test/foo/bar/baz ' , 'hello world ' , ['bar ' ]],
34+ [true , 'test/foo/# ' , 'test/foo/bar/baz ' , 'hello world ' , ['bar/baz ' ]],
35+ [true , 'test/foo/+/bar/# ' , 'test/foo/my/bar/baz ' , 'hello world ' , ['my ' , 'baz ' ]],
36+ [true , 'test/foo/+/bar/# ' , 'test/foo/my/bar/baz/blub ' , 'hello world ' , ['my ' , 'baz/blub ' ]],
37+ [true , 'test/foo/bar/baz ' , 'test/foo/bar/baz ' , random_bytes (2 * 1024 * 1024 ), []], // 2MB message
3038 ];
3139 }
3240
3341 /**
3442 * @dataProvider publishSubscribeData
3543 */
3644 public function test_publishing_and_subscribing_using_quality_of_service_0_works_as_intended (
45+ bool $ useBlockingSocket ,
3746 string $ subscriptionTopicFilter ,
3847 string $ publishTopic ,
3948 string $ publishMessage ,
4049 array $ matchedTopicWildcards
4150 ): void
4251 {
4352 // We connect and subscribe to a topic using the first client.
53+ $ connectionSettings = (new ConnectionSettings ())
54+ ->useBlockingSocket ($ useBlockingSocket );
55+
4456 $ subscriber = new MqttClient ($ this ->mqttBrokerHost , $ this ->mqttBrokerPort , 'subscriber ' );
45- $ subscriber ->connect (null , true );
57+ $ subscriber ->connect ($ connectionSettings , true );
4658
4759 $ subscriber ->subscribe (
4860 $ subscriptionTopicFilter ,
@@ -76,15 +88,19 @@ function (string $topic, string $message, bool $retained, array $wildcards) use
7688 * @dataProvider publishSubscribeData
7789 */
7890 public function test_publishing_and_subscribing_using_quality_of_service_1_works_as_intended (
91+ bool $ useBlockingSocket ,
7992 string $ subscriptionTopicFilter ,
8093 string $ publishTopic ,
8194 string $ publishMessage ,
8295 array $ matchedTopicWildcards
8396 ): void
8497 {
8598 // We connect and subscribe to a topic using the first client.
99+ $ connectionSettings = (new ConnectionSettings ())
100+ ->useBlockingSocket ($ useBlockingSocket );
101+
86102 $ subscriber = new MqttClient ($ this ->mqttBrokerHost , $ this ->mqttBrokerPort , 'subscriber ' );
87- $ subscriber ->connect (null , true );
103+ $ subscriber ->connect ($ connectionSettings , true );
88104
89105 $ subscriber ->subscribe (
90106 $ subscriptionTopicFilter ,
@@ -118,15 +134,19 @@ function (string $topic, string $message, bool $retained, array $wildcards) use
118134 * @dataProvider publishSubscribeData
119135 */
120136 public function test_publishing_and_subscribing_using_quality_of_service_2_works_as_intended (
137+ bool $ useBlockingSocket ,
121138 string $ subscriptionTopicFilter ,
122139 string $ publishTopic ,
123140 string $ publishMessage ,
124141 array $ matchedTopicWildcards
125142 ): void
126143 {
127144 // We connect and subscribe to a topic using the first client.
145+ $ connectionSettings = (new ConnectionSettings ())
146+ ->useBlockingSocket ($ useBlockingSocket );
147+
128148 $ subscriber = new MqttClient ($ this ->mqttBrokerHost , $ this ->mqttBrokerPort , 'subscriber ' );
129- $ subscriber ->connect (null , true );
149+ $ subscriber ->connect ($ connectionSettings , true );
130150
131151 $ subscription = function (string $ topic , string $ message , bool $ retained , array $ wildcards ) use ($ subscriber , $ subscriptionTopicFilter , $ publishTopic , $ publishMessage , $ matchedTopicWildcards ) {
132152 // By asserting something here, we will avoid a no-assertions-in-test warning, making the test pass.
0 commit comments