1212namespace Symfony \Component \Notifier \Bridge \TurboSms \Tests ;
1313
1414use Symfony \Component \HttpClient \MockHttpClient ;
15+ use Symfony \Component \HttpClient \Response \JsonMockResponse ;
1516use Symfony \Component \Notifier \Bridge \TurboSms \TurboSmsTransport ;
1617use Symfony \Component \Notifier \Exception \LengthException ;
1718use Symfony \Component \Notifier \Exception \TransportException ;
@@ -48,28 +49,18 @@ public static function unsupportedMessagesProvider(): iterable
4849
4950 public function testSuccessfulSend ()
5051 {
51- $ response = $ this ->createMock (ResponseInterface::class);
52- $ response
53- ->expects (self ::exactly (2 ))
54-
8000
span> ->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 ' ,
7061 ],
71- ]))
72- ;
62+ ],
63+ ], info: [ ' http_code ' => 200 ]) ;
7364
7465 $ client = new MockHttpClient (static function (string $ method , string $ url , array $ options ) use ($ response ): ResponseInterface {
7566 $ body = json_decode ($ options ['body ' ], true );
@@ -95,28 +86,18 @@ public function testSuccessfulSend()
9586
9687 public function testFailedSendWithPartialAccepted ()
9788 {
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 ' ,
11798 ],
118- ]))
119- ;
99+ ],
100+ ], info: [ ' http_code ' => 200 ]) ;
120101
121102 $ client = new MockHttpClient (static fn () => $ response );
122103
@@ -132,21 +113,11 @@ public function testFailedSendWithPartialAccepted()
132113
133114 public function testFailedSend ()
134115 {
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 ]);
150121
151122 $ client = new MockHttpClient (static fn (): ResponseInterface => $ response );
152123
@@ -165,10 +136,7 @@ public function testInvalidFrom()
165136 $ this ->expectException (LengthException::class);
166137 $ this ->expectExceptionMessage ('The sender length of a TurboSMS message must not exceed 20 characters. ' );
167138
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));
172140 }
173141
174142 public function testInvalidSubjectWithLatinSymbols ()
0 commit comments