12
12
namespace Symfony \Component \Notifier \Bridge \TurboSms \Tests ;
13
13
14
14
use Symfony \Component \HttpClient \MockHttpClient ;
15
+ use Symfony \Component \HttpClient \Response \JsonMockResponse ;
15
16
use Symfony \Component \Notifier \Bridge \TurboSms \TurboSmsTransport ;
16
17
use Symfony \Component \Notifier \Exception \LengthException ;
17
18
use Symfony \Component \Notifier \Exception \TransportException ;
@@ -48,28 +49,18 @@ public static function unsupportedMessagesProvider(): iterable
48
49
49
50
public function testSuccessfulSend ()
50
51
{
51
- $ response = $ this ->createMock (ResponseInterface::class);
52
- $ response
53
- ->expects (self ::exactly (2 ))
54
- ->method ('getStatusCode ' )
55
- ->willReturn (200 )
56
- ;
57
- $ response
58
- ->expects (self ::once ())
59
- ->method ('getContent ' )
60
- ->willReturn (json_encode ([
61
- 'response_code ' => 0 ,
62
- 'response_status ' => 'OK ' ,
63
- 'response_result ' => [
64
- [
65
- 'phone ' => '380931234567 ' ,
66
- 'response_code ' => 0 ,
67
- 'message_id ' => 'f83f8868-5e46-c6cf-e4fb-615e5a293754 ' ,
68
- 'response_status ' => 'OK ' ,
69
- ],
52
+ $ response = new JsonMockResponse (body: [
53
+ 'response_code ' => 0 ,
54
+ 'response_status ' => 'OK ' ,
55
+ 'response_result ' => [
56
+ [
57
+ 'phone ' => '380931234567 ' ,
58
+ 'response_code ' => 0 ,
59
+ 'message_id ' => 'f83f8868-5e46-c6cf-e4fb-615e5a293754 ' ,
60
+ 'response_status ' => 'OK ' ,
70
61
],
71
- ]))
72
- ;
62
+ ],
63
+ ], info: [ ' http_code ' => 200 ]) ;
73
64
74
65
$ client = new MockHttpClient (static function (string $ method , string $ url , array $ options ) use ($ response ): ResponseInterface {
75
66
$ body = json_decode ($ options ['body ' ], true );
@@ -95,28 +86,18 @@ public function testSuccessfulSend()
95
86
96
87
public function testFailedSendWithPartialAccepted ()
97
88
{
98
- $ response = $ this ->createMock (ResponseInterface::class);
99
- $ response
100
- ->expects (self ::exactly (2 ))
101
- ->method ('getStatusCode ' )
102
- ->willReturn (200 )
103
- ;
104
- $ response
105
- ->expects (self ::once ())
106
- ->method ('getContent ' )
107
- ->willReturn (json_encode ([
108
- 'response_code ' => 0 ,
109
- 'response_status ' => 'OK ' ,
110
- 'response_result ' => [
111
- [
112
- 'phone ' => '380931234567 ' ,
113
- 'response_code ' => 406 ,
114
- 'message_id ' => null ,
115
- 'response_status ' => 'NOT_ALLOWED_RECIPIENT_COUNTRY ' ,
116
- ],
89
+ $ response = new JsonMockResponse (body: [
90
+ 'response_code ' => 0 ,
91
+ 'response_status ' => 'OK ' ,
92
+ 'response_result ' => [
93
+ [
94
+ 'phone ' => '380931234567 ' ,
95
+ 'response_code ' => 406 ,
96
+ 'message_id ' => null ,
97
+ 'response_status ' => 'NOT_ALLOWED_RECIPIENT_COUNTRY ' ,
117
98
],
118
- ]))
119
- ;
99
+ ],
100
+ ], info: [ ' http_code ' => 200 ]) ;
120
101
121
102
$ client = new MockHttpClient (static fn () => $ response );
122
103
@@ -132,21 +113,11 @@ public function testFailedSendWithPartialAccepted()
132
113
133
114
public function testFailedSend ()
134
115
{
135
- $ response = $ this ->createMock (ResponseInterface::class);
136
- $ response
137
- ->expects (self ::exactly (2 ))
138
- ->method ('getStatusCode ' )
139
- ->willReturn (400 )
140
- ;
141
- $ response
142
- ->expects (self ::once ())
143
- ->method ('getContent ' )
144
- ->willReturn (json_encode ([
145
- 'response_code ' => 103 ,
146
- 'response_status ' => 'REQUIRED_TOKEN ' ,
147
- 'response_result ' => null ,
148
- ]))
149
- ;
116
+ $ response = new JsonMockResponse (body: [
117
+ 'response_code ' => 103 ,
118
+ 'response_status ' => 'REQUIRED_TOKEN ' ,
119
+ 'response_result ' => null ,
120
+ ], info: ['http_code ' => 400 ]);
150
121
151
122
$ client = new MockHttpClient (static fn (): ResponseInterface => $ response );
152
123
@@ -165,10 +136,7 @@ public function testInvalidFrom()
165
136
$ this ->expectException (LengthException::class);
166
137
$ this ->expectExceptionMessage ('The sender length of a TurboSMS message must not exceed 20 characters. ' );
167
138
168
- $ message = new SmsMessage ('380931234567 ' , 'Hello! ' );
169
- $ transport = new TurboSmsTransport ('authToken ' , 'abcdefghijklmnopqrstu ' , $ this ->createMock (HttpClientInterface::class));
170
-
171
- $ transport ->send ($ message );
139
+ new TurboSmsTransport ('authToken ' , 'abcdefghijklmnopqrstu ' , $ this ->createMock (HttpClientInterface::class));
172
140
}
173
141
174
142
public function testInvalidSubjectWithLatinSymbols ()
0 commit comments