-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ exception handler now aware of request
- Loading branch information
1 parent
c0aa3ff
commit 3d27878
Showing
5 changed files
with
59 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Photogabble\Tuppence\Tests\Unit; | ||
|
||
use \Exception; | ||
use Photogabble\Tuppence\ErrorHandlers\DefaultExceptionHandler; | ||
use Zend\Diactoros\Response\JsonResponse; | ||
use Zend\Diactoros\ServerRequestFactory; | ||
|
||
class DefaultExceptionHandlerTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testResponse() | ||
{ | ||
$handler = new DefaultExceptionHandler(); | ||
$exception = new Exception('Test'); | ||
|
||
$response = $handler($exception, ServerRequestFactory::fromGlobals()); | ||
$this->assertInstanceOf(JsonResponse::class, $response); | ||
|
||
$jsonDecode = json_decode((string) $response->getBody()->getContents(), true); | ||
|
||
$this->assertEquals('Test', $jsonDecode['message']); | ||
|
||
} | ||
|
||
public function testIgnoreFunctionality() | ||
{ | ||
$handler = new DefaultExceptionHandler(); | ||
$handler->addIgnored(Exception::class); | ||
$exception = new Exception('Test'); | ||
|
||
try { | ||
$handler($exception, ServerRequestFactory::fromGlobals()); | ||
} catch (Exception $e) { | ||
$this->assertSame($exception, $e); | ||
} | ||
} | ||
} |