1
1
<?php
2
2
3
- use Dapr \DaprClient ;
4
3
use Dapr \PubSub \CloudEvent ;
5
4
use Dapr \PubSub \Publish ;
6
5
use Dapr \PubSub \Topic ;
@@ -21,15 +20,27 @@ class PublishTest extends DaprTests
21
20
public function testSimplePublish ()
22
21
{
23
22
$ client = $ this ->get_new_client ();
24
- $ client ->expects ($ this ->once ())->method ('publishEvent ' )->with ();
23
+ $ client ->expects ($ this ->once ())->method ('publishEvent ' )->with (
24
+ $ this ->equalTo ('pubsub ' ),
25
+ $ this ->equalTo ('topic ' ),
26
+ $ this ->equalTo (['my ' => 'event ' ]),
27
+ $ this ->equalTo ([]),
28
+ $ this ->equalTo ('application/json ' )
29
+ );
25
30
$ topic = new Topic ('pubsub ' , 'topic ' , $ client );
26
31
$ topic ->publish (['my ' => 'event ' ]);
27
32
}
28
33
29
34
public function testBinaryPublish ()
30
35
{
31
36
$ client = $ this ->get_new_client ();
32
- $ client ->expects ($ this ->once ())->method ('publishEvent ' );
37
+ $ client ->expects ($ this ->once ())->method ('publishEvent ' )->with (
38
+ $ this ->equalTo ('pubsub ' ),
39
+ $ this ->equalTo ('test ' ),
40
+ $ this ->equalTo ('data ' ),
41
+ $ this ->equalTo ([]),
42
+ $ this ->equalTo ('application/octet-stream ' )
43
+ );
33
44
$ topic = new Topic ('pubsub ' , 'test ' , $ client );
34
45
$ topic ->publish ('data ' , content_type: 'application/octet-stream ' );
35
46
}
@@ -40,7 +51,6 @@ public function testBinaryPublish()
40
51
*/
41
52
public function testCloudEventPublish ()
42
53
{
43
- $ publisher = $ this ->container ->make (Publish::class, ['pubsub ' => 'pubsub ' ]);
44
54
$ event = new CloudEvent ();
45
55
$ event ->data = ['my ' => 'event ' ];
46
56
$ event ->type = 'type ' ;
@@ -49,6 +59,30 @@ public function testCloudEventPublish()
49
59
$ event ->data_content_type = 'application/json ' ;
50
60
$ event ->source = 'source ' ;
51
61
$ event ->time = new DateTime ('2020-12-12T20:47:00+00:00Z ' );
62
+
63
+ $ client = $ this ->get_new_client ();
64
+ $ client ->expects ($ this ->once ())->method ('publishEvent ' )->with (
65
+ $ this ->equalTo ('pubsub ' ),
66
+ $ this ->equalTo ('test ' ),
67
+ $ this ->equalTo ([
68
+ 'id ' => 'id ' ,
69
+ 'source ' => 'source ' ,
70
+ 'specversion ' => '1.0 ' ,
71
+ 'type ' => 'type ' ,
72
+ 'datacontenttype ' => 'application/json ' ,
73
+ 'subject ' => 'subject ' ,
74
+ 'time ' => '2020-12-12T20:47:00+00:00Z ' ,
75
+ 'data ' => [
76
+ 'my ' => 'event ' ,
77
+ ],
78
+ ]),
79
+ $ this ->equalTo ([]),
80
+ $ this ->equalTo ('application/cloudevents+json ' )
81
+ );
82
+ $ topic = new Topic ('pubsub ' , 'test ' , $ client );
83
+ $ topic ->publish ($ event );
84
+
85
+ $ publisher = $ this ->container ->make (Publish::class, ['pubsub ' => 'pubsub ' ]);
52
86
$ this ->get_client ()->register_post (
53
87
'/publish/pubsub/topic ' ,
54
88
200 ,
0 commit comments