3
3
namespace Spinen \Discourse \Listeners ;
4
4
5
5
use GuzzleHttp \Client ;
6
+ use GuzzleHttp \Exception \BadResponseException ;
6
7
use GuzzleHttp \Psr7 \Response ;
7
8
use Illuminate \Auth \Events \Logout ;
8
9
use Illuminate \Contracts \Auth \Authenticatable as User ;
9
10
use Illuminate \Contracts \Config \Repository as Config ;
10
11
use Illuminate \Http \Request ;
11
12
use Mockery ;
13
+ use Psr \Http \Message \ResponseInterface ;
14
+ use Ramsey \Collection \AbstractArray ;
12
15
use Spinen \Discourse \TestCase ;
13
16
use Symfony \Component \HttpKernel \Log \Logger ;
14
17
@@ -160,12 +163,13 @@ public function if_it_receives_no_user_it_does_nothing_and_returns()
160
163
/**
161
164
* @test
162
165
*/
163
- public function on_getting_user_if_discourse_response_code_is_not_200_log_a_warning_with_the_status_code ()
166
+ public function on_getting_user_if_discourse_response_code_is_not_200_log_an_error_with_the_status_code ()
164
167
{
165
168
$ this ->user_mock ->id = 1 ;
166
169
$ this ->event_mock ->user = $ this ->user_mock ;
170
+ $ exception_mock = Mockery::mock (BadResponseException::class);
167
171
168
- $ this ->logger_mock ->shouldReceive ('warning ' )->once ();
172
+ $ this ->logger_mock ->shouldReceive ('error ' )->once ();
169
173
170
174
$ configs = [
171
175
'base_uri ' => 'http://discourse.example.com ' ,
@@ -190,6 +194,10 @@ public function on_getting_user_if_discourse_response_code_is_not_200_log_a_warn
190
194
->once ()
191
195
->andReturn ($ configs ['headers ' ]['Api-Username ' ]);
192
196
197
+ $ exception_mock ->shouldReceive ('getResponse ' )
198
+ ->once ()
199
+ ->andReturn ($ this ->response_mock );
200
+
193
201
$ this ->response_mock ->shouldReceive ('getStatusCode ' )
194
202
->andReturn (500 );
195
203
@@ -200,7 +208,8 @@ public function on_getting_user_if_discourse_response_code_is_not_200_log_a_warn
200
208
$ this ->guzzle_mock ->shouldReceive ('get ' )
201
209
->with ('users/by-external/1.json ' , $ configs )
202
210
->once ()
203
- ->andReturn ($ this ->response_mock );
211
+ ->andReturn ($ this ->response_mock )
212
+ ->andThrow ($ exception_mock , 'Bad Response ' , 500 );
204
213
205
214
$ this ->listener ->handle ($ this ->event_mock );
206
215
}
0 commit comments