@@ -19,30 +19,40 @@ class PublishTest extends DaprTests
19
19
*/
20
20
public function testSimplePublish ()
21
21
{
22
- $ client = $ this ->get_new_client ();
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 ' )
22
+ $ container = $ this ->get_http_client_stack (
23
+ [
24
+ new \GuzzleHttp \Psr7 \Response (204 )
25
+ ]
29
26
);
27
+ $ client = $ this ->get_new_client_with_http ($ container ->client );
30
28
$ topic = new Topic ('pubsub ' , 'topic ' , $ client );
31
- $ topic ->publish (['my ' => 'event ' ]);
29
+ $ topic ->publish (['my ' => 'event ' ], ['test ' => 'meta ' ]);
30
+
31
+ $ request = $ container ->history [0 ]['request ' ];
32
+ $ this ->assertRequestMethod ('POST ' , $ request );
33
+ $ this ->assertRequestUri ('/v1.0/publish/pubsub/topic ' , $ request );
34
+ $ this ->assertRequestQueryString ('metadata.test=meta ' , $ request );
35
+ $ this ->assertRequestHasHeaders (['Content-Type ' => 'application/json ' ], $ request );
36
+ $ this ->assertRequestBody (json_encode (['my ' => 'event ' ]), $ request );
32
37
}
33
38
34
39
public function testBinaryPublish ()
35
40
{
36
- $ client = $ this ->get_new_client ();
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 ' )
41
+ $ container = $ this ->get_http_client_stack (
42
+ [
43
+ new \GuzzleHttp \Psr7 \Response (204 ),
44
+ ]
43
45
);
46
+ $ client = $ this ->get_new_client_with_http ($ container ->client );
44
47
$ topic = new Topic ('pubsub ' , 'test ' , $ client );
45
48
$ topic ->publish ('data ' , content_type: 'application/octet-stream ' );
49
+
50
+ $ request = $ container ->history [0 ]['request ' ];
51
+ $ this ->assertRequestMethod ('POST ' , $ request );
52
+ $ this ->assertRequestUri ('/v1.0/publish/pubsub/test ' , $ request );
53
+ $ this ->assertRequestQueryString ('' , $ request );
54
+ $ this ->assertRequestHasHeaders (['Content-Type ' => 'application/octet-stream ' ], $ request );
55
+ $ this ->assertRequestBody ('"data" ' , $ request );
46
56
}
47
57
48
58
/**
@@ -51,6 +61,9 @@ public function testBinaryPublish()
51
61
*/
52
62
public function testCloudEventPublish ()
53
63
{
64
+ $ container = $ this ->get_http_client_stack ([new \GuzzleHttp \Psr7 \Response (204 )]);
65
+ $ client = $ this ->get_new_client_with_http ($ container ->client );
66
+
54
67
$ event = new CloudEvent ();
55
68
$ event ->data = ['my ' => 'event ' ];
56
69
$ event ->type = 'type ' ;
@@ -60,25 +73,6 @@ public function testCloudEventPublish()
60
73
$ event ->source = 'source ' ;
61
74
$ event ->time = new DateTime ('2020-12-12T20:47:00+00:00Z ' );
62
75
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
76
$ topic = new Topic ('pubsub ' , 'test ' , $ client );
83
77
$ topic ->publish ($ event );
84
78
@@ -101,6 +95,16 @@ public function testCloudEventPublish()
101
95
]
102
96
);
103
97
$ publisher ->topic ('topic ' )->publish ($ event );
98
+
99
+ $ request = $ container ->history [0 ]['request ' ];
100
+ $ this ->assertRequestMethod ('POST ' , $ request );
101
+ $ this ->assertRequestUri ('/v1.0/publish/pubsub/test ' , $ request );
102
+ $ this ->assertRequestQueryString ('' , $ request );
103
+ $ this ->assertRequestHasHeaders (['Content-Type ' => 'application/cloudevents+json ' ], $ request );
104
+ $ this ->assertRequestBody (
105
+ '{"id":"id","source":"source","specversion":"1.0","type":"type","datacontenttype":"application\/json","subject":"subject","time":"2020-12-12T20:47:00+00:00Z","data":{"my":"event"}} ' ,
106
+ $ request
107
+ );
104
108
}
105
109
106
110
/**
0 commit comments