8000 [Feature] Allow test exception handler to be used by packages · tekord/laravel-json-api@4075baf · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Feb 17, 2023. It is now read-only.

Commit 4075baf

Browse files
committed
[Feature] Allow test exception handler to be used by packages
Moves the dummy app test exception handler into the `Testing` namespace. This means that it can also be used when testing JSON API packages, e.g. when using `orchestra/testbench`.
1 parent e42d1cc commit 4075baf

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ previously in the `has-many` adapter).
1212
- Moved the `FindsManyResources` trait from the `Store` namespace to `Adapter\Concerns`.
1313
- The `hydrateRelationships` method on the `AbstractResourceAdapter` is no longer abstract as it now
1414
contains the implementation that was previously on the Eloquent adapter.
15+
- The test exception handler has been moved from the dummy app to the `Testing` namespace. This means it
16+
can now be used when testing JSON API packages.
1517

1618
## [1.0.0-alpha.2] - 2018-05-06
1719

tests/dummy/app/Exceptions/Handler.php renamed to src/Testing/TestExceptionHandler.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,38 @@
1515
* limitations under the License.
1616
*/
1717

18-
namespace DummyApp\Exceptions;
18+
namespace CloudCreativity\LaravelJsonApi\Testing;
1919

2020
use CloudCreativity\LaravelJsonApi\Exceptions\HandlesErrors;
2121
use Exception;
2222
use Illuminate\Auth\Access\AuthorizationException;
2323
use Illuminate\Auth\AuthenticationException;
2424
use Neomerx\JsonApi\Exceptions\JsonApiException;
25-
use Orchestra\Testbench\Exceptions\Handler as BaseHandler;
25+
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
2626

27-
class Handler extends BaseHandler
27+
/**
28+
* Class TestExceptionHandler
29+
*
30+
* This exception handler is intended for testing JSON API packages
31+
* using the `orchestra/testbench` package. It ensures that JSON
32+
* API exceptions are rendered and if the handler receives any other
33+
* exceptions, they are re-thrown so that they appear in PHP Unit.
34+
*
35+
* Usage in a testbench test case is as follows:
36+
*
37+
* ```php
38+
* protected function resolveApplicationExceptionHandler($app)
39+
* {
40+
* $app->singleton(
41+
* \Illuminate\Contracts\Debug\ExceptionHandler::class,
42+
* \CloudCreativity\LaravelJsonApi\Testing\TestExceptionHandler::class
43+
* );
44+
* }
45+
* ```
46+
*
47+
* @package CloudCreativity\LaravelJsonApi
48+
*/
49+
class TestExceptionHandler extends ExceptionHandler
2850
{
2951

3052
use HandlesErrors;

tests/lib/Integration/TestCase.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use CloudCreativity\LaravelJsonApi\Facades\JsonApi;
2222
use CloudCreativity\LaravelJsonApi\ServiceProvider;
2323
use CloudCreativity\LaravelJsonApi\Testing\MakesJsonApiRequests;
24+
use CloudCreativity\LaravelJsonApi\Testing\TestExceptionHandler;
2425
use DummyApp;
2526
use DummyApp\User;
2627
use DummyPackage;
@@ -88,7 +89,7 @@ protected function getPackageAliases($app)
8889
*/
8990
protected function resolveApplicationExceptionHandler($app)
9091
{
91-
$app->singleton(ExceptionHandler::class, DummyApp\Exceptions\Handler::class);
92+
$app->singleton(ExceptionHandler::class, TestExceptionHandler::class);
9293
}
9394

9495
/**

0 commit comments

Comments
 (0)
0