This repository has been archived by the owner on Jan 2, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhance invalid parameter exceptions. closes #96
- Loading branch information
1 parent
0feda5d
commit d9eccd9
Showing
5 changed files
with
115 additions
and
5 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
44 changes: 44 additions & 0 deletions
44
tests/Exception/Handler/InvalidParameterExceptionHandlerTest.php
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,44 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of JSON-API. | ||
* | ||
* (c) Toby Zerner <toby.zerner@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Tobscure\Tests\Exception\Handler; | ||
|
||
use Exception; | ||
use Tobscure\JsonApi\Exception\Handler\InvalidParameterExceptionHandler; | ||
use Tobscure\JsonApi\Exception\Handler\ResponseBag; | ||
use Tobscure\JsonApi\Exception\InvalidParameterException; | ||
|
||
class InvalidParameterExceptionHandlerTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testHandlerCanManageInvalidParameterExceptions() | ||
{ | ||
$handler = new InvalidParameterExceptionHandler(); | ||
|
||
$this->assertTrue($handler->manages(new InvalidParameterException)); | ||
} | ||
|
||
public function testHandlerCanNotManageOtherExceptions() | ||
{ | ||
$handler = new InvalidParameterExceptionHandler(); | ||
|
||
$this->assertFalse($handler->manages(new Exception)); | ||
} | ||
|
||
public function testErrorHandling() | ||
{ | ||
$handler = new InvalidParameterExceptionHandler(); | ||
$response = $handler->handle(new InvalidParameterException('error', 1, null, 'include')); | ||
|
||
$this->assertInstanceOf(ResponseBag::class, $response); | ||
$this->assertEquals(400, $response->getStatus()); | ||
$this->assertEquals([['code' => 1, 'source' => ['parameter' => 'include']]], $response->getErrors()); | ||
} | ||
} |
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