From bffdb151eae58c6a300c125824eb64f63e5414a9 Mon Sep 17 00:00:00 2001 From: printempw Date: Sun, 12 Aug 2018 20:42:40 +0800 Subject: [PATCH] Fix MarketControllerTest::testGetMarketData --- tests/Concerns/FakeExceptionHandler.php | 21 +++++++++++++++++++ tests/MarketControllerTest.php | 3 +-- tests/TestCase.php | 27 +++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 tests/Concerns/FakeExceptionHandler.php 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 () {