@@ -49,15 +49,15 @@ public function unsupportedMessagesProvider(): iterable
49
49
public function testSendWithErrorResponseThrowsTransportException ()
50
50
{
51
51
$ this ->expectException (TransportException::class);
52
- $ this ->expectExceptionMessageMatches ('/testDescription.+testErrorCode / ' );
52
+ $ this ->expectExceptionMessageMatches ('/post.+ testDescription.+400 / ' );
53
53
54
54
$ response = $ this ->createMock (ResponseInterface::class);
55
55
$ response ->expects ($ this ->exactly (2 ))
56
56
->method ('getStatusCode ' )
57
57
->willReturn (400 );
58
58
$ response ->expects ($ this ->once ())
59
59
->method ('getContent ' )
60
- ->willReturn (json_encode (['description ' => 'testDescription ' , 'error_code ' => ' testErrorCode ' ]));
60
+ ->willReturn (json_encode (['description ' => 'testDescription ' , 'error_code ' => 400 ]));
61
61
62
62
$ client = new MockHttpClient (static function () use ($ response ): ResponseInterface {
63
63
return $ response ;
@@ -68,6 +68,28 @@ public function testSendWithErrorResponseThrowsTransportException()
68
68
$ transport ->send (new ChatMessage ('testMessage ' ));
69
69
}
70
70
71
+ public function testSendWithErrorResponseThrowsTransportExceptionForEdit ()
72
+ {
73
+ $ this ->expectException (TransportException::class);
74
+ $ this ->expectExceptionMessageMatches ('/edit.+testDescription.+404/ ' );
75
+
76
+ $ response = $ this ->createMock (ResponseInterface::class);
77
+ $ response ->expects ($ this ->exactly (2 ))
78
+ ->method ('getStatusCode ' )
79
+ ->willReturn (400 );
80
+ $ response ->expects ($ this ->once ())
81
+ ->method ('getContent ' )
82
+ ->willReturn (json_encode (['description ' => 'testDescription ' , 'error_code ' => 404 ]));
83
+
84
+ $ client = new MockHttpClient (static function () use ($ response ): ResponseInterface {
85
+ return $ response ;
86
+ });
87
+
88
+ $ transport = $ this ->createTransport ($ client , 'testChannel ' );
89
+
90
+ $ transport ->send (new ChatMessage ('testMessage ' , (new TelegramOptions ())->edit (123 )));
91
+ }
92
+
71
93
public function testSendWithOptions ()
72
94
{
73
95
$ response = $ this ->createMock (ResponseInterface::class);
@@ -110,6 +132,7 @@ public function testSendWithOptions()
110
132
];
111
133
112
134
$ client = new MockHttpClient (function (string $ method , string $ url , array $ options = []) use ($ response , $ expectedBody ): ResponseInterface {
135
+ $ this ->assertStringEndsWith ('/sendMessage ' , $ url );
113
136
$ this ->assertSame ($ expectedBody , json_decode ($ options ['body ' ], true ));
114
137
115
138
return $ response ;
@@ -123,6 +146,53 @@ public function testSendWithOptions()
123
146
$ this ->assertEquals ('telegram://api.telegram.org?channel=testChannel ' , $ sentMessage ->getTransport ());
124
147
}
125
148
149
+ public function testSendWithOptionForEditMessage ()
150
+ {
151
+ $ response = $ this ->createMock (ResponseInterface::class);
152
+ $ response ->expects ($ this ->exactly (2 ))
153
+ ->method ('getStatusCode ' )
154
+ ->willReturn (200 );
155
+
156
+ $ content = <<<JSON
157
+ {
158
+ "ok": true,
159
+ "result": {
160
+ "message_id": 1,
161
+ "from": {
162
+ "id": 12345678,
163
+ "first_name": "YourBot",
164
+ "username": "YourBot"
165
+ },
166
+ "chat": {
167
+ "id": 1234567890,
168
+ "first_name": "John",
169
+ "last_name": "Doe",
170
+ "username": "JohnDoe",
171
+ "type": "private"
172
+ },
173
+ "date": 1459958199,
174
+ "text": "Hello from Bot!"
175
+ }
176
+ }
177
+ JSON ;
178
+
179
+ $ response ->expects ($ this ->once ())
180
+ ->method ('getContent ' )
181
+ ->willReturn ($ content )
182
+ ;
183
+
184
+ $ client = new MockHttpClient (function (string $ method , string $ url ) use ($ response ): ResponseInterface {
185
+ $ this ->assertStringEndsWith ('/editMessageText ' , $ url );
186
+
187
+ return $ response ;
188
+ });
189
+
190
+ $ transport = $ this ->createTransport ($ client , 'testChannel ' );
191
+ $ options = (new TelegramOptions ())->edit (123 );
192
+
193
+ $ transport ->send (new ChatMessage ('testMessage ' , $ options ));
194
+ }
195
+
126
196
public function testSendWithChannelOverride ()
127
197
{
128
198
$ channelOverride = 'channelOverride ' ;
0 commit comments