Skip to content

Commit 51d9db9

Browse files
committed
Fill in test coverage
1 parent 18f06d3 commit 51d9db9

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

tests/Listeners/LogoutDiscourseUserTest.php

+12-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
namespace Spinen\Discourse\Listeners;
44

55
use GuzzleHttp\Client;
6+
use GuzzleHttp\Exception\BadResponseException;
67
use GuzzleHttp\Psr7\Response;
78
use Illuminate\Auth\Events\Logout;
89
use Illuminate\Contracts\Auth\Authenticatable as User;
910
use Illuminate\Contracts\Config\Repository as Config;
1011
use Illuminate\Http\Request;
1112
use Mockery;
13+
use Psr\Http\Message\ResponseInterface;
14+
use Ramsey\Collection\AbstractArray;
1215
use Spinen\Discourse\TestCase;
1316
use Symfony\Component\HttpKernel\Log\Logger;
1417

@@ -160,12 +163,13 @@ public function if_it_receives_no_user_it_does_nothing_and_returns()
160163
/**
161164
* @test
162165
*/
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()
164167
{
165168
$this->user_mock->id = 1;
166169
$this->event_mock->user = $this->user_mock;
170+
$exception_mock = Mockery::mock(BadResponseException::class);
167171

168-
$this->logger_mock->shouldReceive('warning')->once();
172+
$this->logger_mock->shouldReceive('error')->once();
169173

170174
$configs = [
171175
'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
190194
->once()
191195
->andReturn($configs['headers']['Api-Username']);
192196

197+
$exception_mock->shouldReceive('getResponse')
198+
->once()
199+
->andReturn($this->response_mock);
200+
193201
$this->response_mock->shouldReceive('getStatusCode')
194202
->andReturn(500);
195203

@@ -200,7 +208,8 @@ public function on_getting_user_if_discourse_response_code_is_not_200_log_a_warn
200208
$this->guzzle_mock->shouldReceive('get')
201209
->with('users/by-external/1.json', $configs)
202210
->once()
203-
->andReturn($this->response_mock);
211+
->andReturn($this->response_mock)
212+
->andThrow($exception_mock, 'Bad Response', 500);
204213

205214
$this->listener->handle($this->event_mock);
206215
}

0 commit comments

Comments
 (0)