13
13
14
14
use Symfony \Component \HttpClient \MockHttpClient ;
15
15
use Symfony \Component \Notifier \Bridge \Slack \SlackOptions ;
16
+ use Symfony \Component \Notifier \Bridge \Slack \SlackSentMessage ;
16
17
use Symfony \Component \Notifier \Bridge \Slack \SlackTransport ;
18
+ use Symfony \Component \Notifier \Bridge \Slack \UpdateMessageSlackOptions ;
17
19
use Symfony \Component \Notifier \Exception \InvalidArgumentException ;
18
20
use Symfony \Component \Notifier \Exception \LogicException ;
19
21
use Symfony \Component \Notifier \Exception \TransportException ;
@@ -115,7 +117,7 @@ public function testSendWithOptions()
115
117
116
118
$ response ->expects ($ this ->once ())
117
119
->method ('getContent ' )
118
- ->willReturn (json_encode (['ok ' => true , 'ts ' => '1503435956.000247 ' ]));
120
+ ->willReturn (json_encode (['ok ' => true , 'ts ' => '1503435956.000247 ' , ' channel ' => ' C123456 ' ]));
119
121
120
122
$ expectedBody = json_encode (['channel ' => $ channel , 'text ' => $ message ]);
121
123
@@ -130,6 +132,8 @@ public function testSendWithOptions()
130
132
$ sentMessage = $ transport ->send (new ChatMessage ('testMessage ' ));
131
133
132
134
$ this ->assertSame ('1503435956.000247 ' , $ sentMessage ->getMessageId ());
135
+ $ this ->assertInstanceOf (SlackSentMessage::class, $ sentMessage );
136
+ $ this ->assertSame ('C123456 ' , $ sentMessage ->getChannelId ());
133
137
}
134
138
135
139
public function testSendWithNotification ()
@@ -145,7 +149,7 @@ public function testSendWithNotification()
145
149
146
150
$ response ->expects ($ this ->once ())
147
151
->method ('getContent ' )
148
- ->willReturn (json_encode (['ok ' => true , 'ts ' => '1503435956.000247 ' ]));
152
+ ->willReturn (json_encode (['ok ' => true , 'ts ' => '1503435956.000247 ' , ' channel ' => ' C123456 ' ]));
149
153
150
154
$ notification = new Notification ($ message );
151
155
$ chatMessage = ChatMessage::fromNotification ($ notification );
@@ -223,7 +227,7 @@ public function testSendIncludesContentTypeWithCharset()
223
227
224
228
$ response ->expects ($ this ->once ())
225
229
->method ('getContent ' )
226
- ->willReturn (json_encode (['ok ' => true , 'ts ' => '1503435956.000247 ' ]));
230
+ ->willReturn (json_encode (['ok ' => true , 'ts ' => '1503435956.000247 ' , ' channel ' => ' C123456 ' ]));
227
231
228
232
$ client = new MockHttpClient (function (string $ method , string $ url , array $ options = []) use ($ response ): ResponseInterface {
229
233
$ this ->assertContains ('Content-Type: application/json; charset=utf-8 ' , $ options ['headers ' ]);
@@ -263,4 +267,39 @@ public function testSendWithErrorsIncluded()
263
267
264
268
$ transport ->send (new ChatMessage ('testMessage ' ));
265
269
}
270
+
271
+ public function testUpdateMessage ()
272
+ {
273
+ $ response = $ this ->createMock (ResponseInterface::class);
274
+
275
+ $ response ->expects ($ this ->exactly (2 ))
276
+ ->method ('getStatusCode ' )
277
+ ->willReturn (200 );
278
+
279
+ $ response ->expects ($ this ->once ())
280
+ ->method ('getContent ' )
281
+ ->willReturn (json_encode (['ok ' => true , 'ts ' => '1503435956.000247 ' , 'channel ' => 'C123456 ' ]));
282
+
283
+ $ sentMessage = new SlackSentMessage (new ChatMessage ('Hello ' ), 'slack ' , 'C123456 ' , '1503435956.000247 ' );
284
+ $ chatMessage = $ sentMessage ->getUpdateMessage ('Hello World ' );
285
+
286
+ $ expectedBody = json_encode ([
287
+ 'channel ' => 'C123456 ' ,
288
+ 'ts ' => '1503435956.000247 ' ,
289
+ 'text ' => 'Hello World ' ,
290
+ ]);
291
+
292
+ $ client = new MockHttpClient (function (string $ method , string $ url , array $ options = []) use ($ response , $ expectedBody ): ResponseInterface {
293
+ $ this ->assertJsonStringEqualsJsonString ($ expectedBody , $ options ['body ' ]);
294
+ $ this ->assertStringEndsWith ('chat.update ' , $ url );
295
+
296
+ return $ response ;
297
+ });
298
+
299
+ $ transport = $ this ->createTransport ($ client , 'another-channel ' );
300
+
301
+ $ sentMessage = $ transport ->send ($ chatMessage );
302
+
303
+ $ this ->assertSame ('1503435956.000247 ' , $ sentMessage ->getMessageId ());
304
+ }
266
305
}
0 commit comments