Skip to content

Commit

Permalink
Add test.
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
  • Loading branch information
crynobone committed Apr 10, 2020
1 parent 7b9eeda commit 9cf9aa3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Exceptions/RequestException.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public function getRpcErrorData()
public function report(): void
{
Log::error($this->getMessage(), [
'rpc-error' => $this->getRpcErrorData(),
'method' => $this->getRequestMethod(),
'error' => $this->getRpcErrorData(),
'exception' => $this,
]);
}
Expand Down
34 changes: 34 additions & 0 deletions tests/Feature/Exceptions/RequestExceptionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Minions\Tests\Feature\Exceptions;

use Illuminate\Support\Facades\Log;
use Minions\Client\Response;
use Minions\Exceptions\RequestException;
use Minions\Tests\TestCase;
use Mockery as m;

class RequestExceptionTest extends TestCase
{
/** @test */
public function it_can_report_exception_to_laravel()
{
$response = m::mock(Response::class);

$response->shouldReceive('getRpcErrorData')->once()->andReturn([
'username' => 'The username field is required.',
]);

$exception = new RequestException('The given data was invalid.', -32602, $response, 'users.auth');

Log::shouldReceive('error')->once()->andReturnUsing(function ($message, $context) {
$this->assertSame('The given data was invalid.', $message);

$this->assertSame('users.auth', $context['method']);
$this->assertSame(['username' => 'The username field is required.'], $context['error']);
$this->assertInstanceOf(RequestException::class, $context['exception']);
});

$exception->report();
}
}

0 comments on commit 9cf9aa3

Please sign in to comment.