Fix MarketControllerTest::testGetMarketData

This commit is contained in:
printempw 2018-08-12 20:42:40 +08:00
parent 59c9a599fc
commit bffdb151ea
3 changed files with 49 additions and 2 deletions

View 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;
}
}

View File

@ -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');
}
}

View File

@ -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 () {