@@ -26,29 +26,17 @@ final class TelegramTransportTest extends TestCase
26
26
{
27
27
public function testToStringContainsProperties (): void
28
28
{
29
- $ host = 'testHost ' ;
30
29
$ channel = 'testChannel ' ;
31
30
32
- $ transport = new TelegramTransport (
33
- 'testToken ' ,
34
- $ channel ,
35
- $ this ->createMock (HttpClientInterface::class)
36
- );
31
+ $ transport = new TelegramTransport ('testToken ' , $ channel , $ this ->createMock (HttpClientInterface::class));
37
32
$ transport ->setHost ('testHost ' );
38
33
39
- $ this ->assertSame (
40
- sprintf ('telegram://%s?channel=%s ' , $ host , $ channel ),
41
- (string ) $ transport
42
- );
34
+ $ this ->assertSame (sprintf ('telegram://%s?channel=%s ' , 'testHost ' , $ channel ), (string ) $ transport );
43
35
}
44
36
45
37
public function testSupportsChatMessage (): void
46
38
{
47
- $ transport = new TelegramTransport (
48
- 'testToken ' ,
49
- 'testChannel ' ,
50
- $ this ->createMock (HttpClientInterface::class)
51
- );
39
+ $ transport = new TelegramTransport ('testToken ' , 'testChannel ' , $ this ->createMock (HttpClientInterface::class));
52
40
53
41
$ this ->assertTrue ($ transport ->supports (new ChatMessage ('testChatMessage ' )));
54
42
$ this ->assertFalse ($ transport ->supports ($ this ->createMock (MessageInterface::class)));
@@ -57,20 +45,13 @@ public function testSupportsChatMessage(): void
57
45
public function testSendNonChatMessageThrows (): void
58
46
{
59
47
$ this ->expectException (LogicException::class);
60
- $ transport = new TelegramTransport (
61
- 'testToken ' ,
62
- 'testChannel ' ,
63
- $ this ->createMock (HttpClientInterface::class)
64
- );
48
+ $ transport = new TelegramTransport ('testToken ' , 'testChannel ' , $ this ->createMock (HttpClientInterface::class));
65
49
66
50
$ transport ->send ($ this ->createMock (MessageInterface::class));
67
51
}
68
52
69
53
public function testSendWithErrorResponseThrows (): void
70
54
{
71
- $ description = 'testDescription ' ;
72
- $ errorCode = 'testErrorCode ' ;
73
-
74
55
$ this ->expectException (TransportException::class);
75
56
$ this ->expectExceptionMessageRegExp ('/testDescription.+testErrorCode/ ' );
76
57
@@ -80,25 +61,20 @@ public function testSendWithErrorResponseThrows(): void
80
61
->willReturn (400 );
81
62
$ response ->expects ($ this ->once ())
82
63
->method ('getContent ' )
83
- ->willReturn (json_encode (['description ' => $ description , 'error_code ' => $ errorCode ]));
64
+ ->willReturn (json_encode (['description ' => ' testDescription ' , 'error_code ' => ' testErrorCode ' ]));
84
65
85
66
$ client = new MockHttpClient (static function () use ($ response ): ResponseInterface {
86
67
return $ response ;
87
68
});
88
69
89
- $ transport = new TelegramTransport (
90
- 'testToken ' ,
91
- 'testChannel ' ,
92
- $ client
93
- );
70
+ $ transport = new TelegramTransport ('testToken ' , 'testChannel ' , $ client );
94
71
95
72
$ transport ->send (new ChatMessage ('testMessage ' ));
96
73
}
97
74
98
75
public function testSendWithOptions (): void
99
76
{
100
77
$ channel = 'testChannel ' ;
101
- $ message = 'testMessage ' ;
102
78
103
79
$ response = $ this ->createMock (ResponseInterface::class);
104
80
$ response ->expects ($ this ->exactly (2 ))
@@ -110,7 +86,7 @@ public function testSendWithOptions(): void
110
86
111
87
$ expectedBody = [
112
88
'chat_id ' => $ channel ,
113
- 'text ' => $ message ,
89
+ 'text ' => ' testMessage ' ,
114
90
'parse_mode ' => 'Markdown ' ,
115
91
];
116
92
@@ -120,20 +96,14 @@ public function testSendWithOptions(): void
120
96
return $ response ;
121
97
});
122
98
123
- $ transport = new TelegramTransport (
124
- 'testToken ' ,
125
- $ channel ,
126
- $ client
127
- );
99
+ $ transport = new TelegramTransport ('testToken ' , $ channel , $ client );
128
100
129
101
$ transport ->send (new ChatMessage ('testMessage ' ));
130
102
}
131
103
132
104
public function testSendWithChannelOverride (): void
133
105
{
134
- $ channel = 'defaultChannel ' ;
135
106
$ channelOverride = 'channelOverride ' ;
136
- $ message = 'testMessage ' ;
137
107
138
108
$ response = $ this ->createMock (ResponseInterface::class);
139
109
$ response ->expects ($ this ->exactly (2 ))
@@ -145,7 +115,7 @@ public function testSendWithChannelOverride(): void
145
115
146
116
$ expectedBody = [
147
117
'chat_id ' => $ channelOverride ,
148
- 'text ' => $ message ,
118
+ 'text ' => ' testMessage ' ,
149
119
'parse_mode ' => 'Markdown ' ,
150
120
];
151
121
@@ -155,11 +125,7 @@ public function testSendWithChannelOverride(): void
155
125
return $ response ;
156
126
});
157
127
158
- $ transport = new TelegramTransport (
159
- 'testToken ' ,
160
- $ channel ,
161
- $ client
162
- );
128
+ $ transport = new TelegramTransport ('testToken ' , 'defaultChannel ' , $ client );
163
129
164
130
$ messageOptions = $ this ->createMock (MessageOptionsInterface::class);
165
131
$ messageOptions
0 commit comments