Skip to content

Commit

Permalink
Hitting 100% tests coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
aronnebrivio committed Mar 21, 2021
1 parent 6863cd5 commit a072563
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
4 changes: 4 additions & 0 deletions app/Classes/ParseInputStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
* Original Gist at:
* https://gist.github.com/jas-/5c3fdc26fedd11cb9fb5#file-class-stream-php
*/

/**
* @codeCoverageIgnore
*/
class ParseInputStream
{
/**
Expand Down
14 changes: 6 additions & 8 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\Exceptions;

use ErrorException;
use Exception;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
Expand All @@ -11,7 +10,6 @@
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
use Throwable;
use UnexpectedValueException;

class Handler extends ExceptionHandler
{
Expand All @@ -38,9 +36,12 @@ class Handler extends ExceptionHandler
*/
public function report(Throwable $e)
{
// Ignoring this block because only applies on production environment
// @codeCoverageIgnoreStart
if (app()->environment('production') && app()->bound('sentry') && $this->shouldReport($e)) {
app('sentry')->captureException($e);
}
// @codeCoverageIgnoreEnd

parent::report($e);
}
Expand All @@ -61,19 +62,16 @@ public function render($request, Throwable $e)
if ($e instanceof MethodNotAllowedHttpException) {
return response('Method Not Allowed.', 405);
}
if ($e instanceof UnexpectedValueException) {
return response('Unexpected value.', 422);
}
if ($e instanceof ModelNotFoundException) {
return response('The resource you are looking for is not available or does not belong to you.', 404);
}
if ($e instanceof ErrorException) {
return response('Unprocessable. Please provide all inputs and retry.', 422);
}
if ($e instanceof AuthorizationException) {
return response($e->getMessage(), 401);
}

// Ignoring this block because only applies if an error is not handled (like 500 server errors)
// @codeCoverageIgnoreStart
return response($e->getMessage(), $e->getCode() ?: 500);
// @codeCoverageIgnoreEnd
}
}
2 changes: 1 addition & 1 deletion tests/AuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function testRefresh()
// NOTE: in order to make logout() function working we have to pass the JWT token -> can't use standard actingAs function
$token = JWTAuth::fromUser($user);

$this->json('POST', 'auth/refresh', [], ['Authorization' => 'Bearer ' . $token])
$this->post('auth/refresh', [], ['Authorization' => 'Bearer ' . $token])
->seeStatusCode(200)
->seeJson(['token_type' => 'bearer']);
}
Expand Down

0 comments on commit a072563

Please sign in to comment.