Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On testing exceptions Collision should not render exceptions #9

Closed
nunomaduro opened this issue Oct 11, 2017 · 7 comments
Closed

On testing exceptions Collision should not render exceptions #9

nunomaduro opened this issue Oct 11, 2017 · 7 comments
Labels

Comments

@nunomaduro
Copy link
Owner

In Laravel, we may want to test if an exception is throw correctly. Given the following routes/web.php:

Route::get('/', function () {
    throw new Exception("This is an exception");
});

And the following test:

$response = $this->get('/');
$response->assertStatus(500);

Our application exception handler should not render an exception.

@nunomaduro nunomaduro added the bug label Oct 11, 2017
@nunomaduro nunomaduro changed the title On testing an exception collision should not render an exception On testing an exceptions Collision should not render an exceptions Oct 11, 2017
@nunomaduro nunomaduro changed the title On testing an exceptions Collision should not render an exceptions On testing exceptions Collision should not render exceptions Oct 12, 2017
@bobbybouwmann
Copy link

I think you need some kind of middleware to that, or tweak your exception handler. Not sure if this should be package specific. Just my two cents!

If I have some time left today I will look into this a bit more ;)

@nunomaduro
Copy link
Owner Author

nunomaduro commented Oct 18, 2017

@bobbybouwmann Thanks for those two cents! I may dive into this issue this weekend 😎

@san4io
Copy link

san4io commented Oct 19, 2017

I think it also shouldn't react in tests to default exceptions like: Validation, Unauthorized, Unauthenticated.

I'm writing test and expect to get 401, of course it passes, but dunno if your listener should catch such exceptions, or maybe it would be great to have ignoredExceptions configuration:

$response = $this->json('GET', '/api/v1/claims');

$response->assertStatus(401);
Illuminate\Auth\AuthenticationException : Unauthenticated.

  at /var/www/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php: 66
  62:                 return $this->auth->shouldUse($guard);
  63:             }
  64:         }
  65: 
  66:         throw new AuthenticationException('Unauthenticated.', $guards);
  67:     }
  68: }
  69: 

All in all, awesome package. :)

@nunomaduro
Copy link
Owner Author

@san4io Thanks for the feedback and for your suggestion!

I will definitely find something this issue. I just didn't have 5 mins minutes to look into to it. I may check tomorrow!

@nunomaduro
Copy link
Owner Author

nunomaduro commented Oct 22, 2017

@bobbybouwmann @san4io I was thinking about using the method $this->shouldReport($e) to understand if collision should render the exception on testing environment.

Like committed on this hot-fix branch: ae9f452

Like that, all Laravel Internal exceptions are ignored on testing env by Collision. What do you guys think? 😊

Other option, is just render an exception via Collision when the status code is 500.

@nunomaduro
Copy link
Owner Author

The version v1.1.6 should have this problem fixed.

@bobbybouwmann
Copy link

This looks pretty good to me! Great job on this :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants