This repository was archived by the owner on Feb 18, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +18
-1
lines changed Expand file tree Collapse file tree 5 files changed +18
-1
lines changed Original file line number Diff line number Diff line change 55use Dingo \Api \Routing \Helpers ;
66use Illuminate \Support \ServiceProvider ;
77use App \Exceptions \BodyTooLargeException ;
8+ use Dingo \Api \Exception \ResourceException ;
89use Illuminate \Auth \AuthenticationException ;
10+ use Illuminate \Validation \ValidationException ;
911use Illuminate \Database \Eloquent \ModelNotFoundException ;
1012
1113class ErrorHandlerServiceProvider extends ServiceProvider
@@ -39,5 +41,12 @@ public function register()
3941 app ('Dingo\Api\Exception\Handler ' )->register (function (BodyTooLargeException $ exception ) {
4042 return $ this ->response ->error ('The body is too large ' , 413 );
4143 });
44+ app ('Dingo\Api\Exception\Handler ' )->register (function (ValidationException $ exception ) {
45+ if (request ()->expectsJson ()) {
46+ throw new ResourceException ('Validation Error ' , $ exception ->errors ());
47+ }
48+
49+ return redirect ()->back ()->withInput (request ()->input ())->withErrors ($ exception ->errors ());
50+ });
4251 }
4352}
Original file line number Diff line number Diff line change 22
33namespace Tests \Feature \Users ;
44
5- use App \Entities \Permission ;
65use Tests \TestCase ;
76use App \Entities \User ;
7+ use App \Entities \Permission ;
88use Laravel \Passport \Passport ;
9+ use Spatie \Permission \PermissionRegistrar ;
910use Illuminate \Foundation \Testing \DatabaseMigrations ;
1011
1112class PermissionsEndpointsTest extends TestCase
@@ -18,6 +19,7 @@ function setUp()
1819 {
1920 parent ::setUp ();
2021 $ this ->installApp ();
22+ $ this ->app ->make (PermissionRegistrar::class)->registerPermissions ();
2123 }
2224
2325 function test_it_can_list_permissions ()
Original file line number Diff line number Diff line change 66use App \Entities \User ;
77use Laravel \Passport \Passport ;
88use Illuminate \Contracts \Hashing \Hasher ;
9+ use Spatie \Permission \PermissionRegistrar ;
910use Illuminate \Foundation \Testing \DatabaseMigrations ;
1011
1112class ProfileEndpointsTest extends TestCase
@@ -17,6 +18,7 @@ function setUp()
1718 {
1819 parent ::setUp ();
1920 $ this ->installApp ();
21+ $ this ->app ->make (PermissionRegistrar::class)->registerPermissions ();
2022 }
2123
2224 function test_it_gets_user_profile ()
Original file line number Diff line number Diff line change 77use App \Entities \Role ;
88use App \Entities \Permission ;
99use Laravel \Passport \Passport ;
10+ use Spatie \Permission \PermissionRegistrar ;
1011use Illuminate \Foundation \Testing \DatabaseMigrations ;
1112
1213class RolesEndpointsTest extends TestCase
@@ -18,6 +19,7 @@ function setUp()
1819 {
1920 parent ::setUp ();
2021 $ this ->installApp ();
22+ $ this ->app ->make (PermissionRegistrar::class)->registerPermissions ();
2123 }
2224
2325
Original file line number Diff line number Diff line change 66use Tests \TestCase ;
77use App \Entities \User ;
88use Laravel \Passport \Passport ;
9+ use Spatie \Permission \PermissionRegistrar ;
910use Illuminate \Foundation \Testing \DatabaseMigrations ;
1011
1112class UsersEndpointsTest extends TestCase
@@ -17,6 +18,7 @@ function setUp()
1718 {
1819 parent ::setUp ();
1920 $ this ->installApp ();
21+ $ this ->app ->make (PermissionRegistrar::class)->registerPermissions ();
2022 }
2123
2224 function test_it_responds_unauthenticated_for_list_users ()
You can’t perform that action at this time.
0 commit comments