diff --git a/tests/Concerns/FakeExceptionHandler.php b/tests/Concerns/FakeExceptionHandler.php new file mode 100644 index 00000000..8967148c --- /dev/null +++ b/tests/Concerns/FakeExceptionHandler.php @@ -0,0 +1,21 @@ + '']); - $this->setExpectedException('Error')->post('/admin/plugins/market-data'); + $this->expectException(Exception::class)->post('/admin/plugins/market-data'); } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 96c8b882..51838667 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -45,6 +45,33 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase return $this->withSession(['uid' => $role->uid, 'token' => $role->getToken()]); } + /** + * Disable Laravel's exception handling. + * + * @see https://laracasts.com/discuss/channels/testing/testing-that-exception-was-thrown + * @return $this + */ + protected function disableExceptionHandling() + { + $this->app->instance(App\Exceptions\Handler::class, new FakeExceptionHandler); + + return $this; + } + + /** + * Set an expected exception. + * + * @param string $class + * @return $this + */ + protected function expectException($class) + { + $this->disableExceptionHandling(); + $this->setExpectedException($class); + + return $this; + } + protected function tearDown() { $this->beforeApplicationDestroyed(function () {