Fix MarketControllerTest::testGetMarketData
This commit is contained in:
parent
59c9a599fc
commit
bffdb151ea
21
tests/Concerns/FakeExceptionHandler.php
Normal file
21
tests/Concerns/FakeExceptionHandler.php
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @see TestCase::disableExceptionHandling
|
||||
*/
|
||||
class FakeExceptionHandler extends App\Exceptions\Handler
|
||||
{
|
||||
public function __construct() {
|
||||
//
|
||||
}
|
||||
|
||||
public function report(Exception $e) {
|
||||
//
|
||||
}
|
||||
|
||||
public function render($request, Exception $e)
|
||||
{
|
||||
// Just re-throw the exception
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
|
@ -47,13 +47,12 @@ class MarketControllerTest extends TestCase
|
|||
'description',
|
||||
'author',
|
||||
'dist',
|
||||
'enabled',
|
||||
'dependencies'
|
||||
]]
|
||||
]);
|
||||
|
||||
// Get plugins info without an valid certificate
|
||||
config(['secure.certificates' => '']);
|
||||
$this->setExpectedException('Error')->post('/admin/plugins/market-data');
|
||||
$this->expectException(Exception::class)->post('/admin/plugins/market-data');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 () {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user