Exception handling: Added NullHandler to be used in commands

main
Igor Scheller 5 years ago committed by msquare
parent 272be5eab2
commit 21ee2bd0d7

@ -5,6 +5,8 @@ use Composer\Autoload\ClassLoader;
use Engelsystem\Application;
use Engelsystem\Database\Migration\Migrate;
use Engelsystem\Database\Migration\MigrationServiceProvider;
use Engelsystem\Exceptions\Handler;
use Engelsystem\Exceptions\Handlers\NullHandler;
require_once __DIR__ . '/../includes/application.php';
@ -15,6 +17,10 @@ $baseDir = __DIR__ . '/../db/migrations';
$app = app();
$app->register(MigrationServiceProvider::class);
/** @var Handler $errorHandler */
$errorHandler = $app->get(Handler::class);
$errorHandler->setHandler(Handler::ENV_PRODUCTION, new NullHandler());
/** @var Migrate $migration */
$migration = $app->get('db.migration');
$migration->setOutput(function ($text) { echo $text . PHP_EOL; });

@ -0,0 +1,18 @@
<?php
namespace Engelsystem\Exceptions\Handlers;
use Engelsystem\Http\Request;
use Throwable;
class NullHandler extends Legacy
{
/**
* @param Request $request
* @param Throwable $e
*/
public function render($request, Throwable $e)
{
return;
}
}

@ -0,0 +1,24 @@
<?php
namespace Engelsystem\Test\Unit\Exceptions\Handlers;
use Engelsystem\Exceptions\Handlers\NullHandler;
use Engelsystem\Http\Request;
use ErrorException;
use PHPUnit\Framework\TestCase;
class NullHandlerTest extends TestCase
{
/**
* @covers \Engelsystem\Exceptions\Handlers\NullHandler::render
*/
public function testRender()
{
$handler = new NullHandler();
$request = new Request();
$exception = new ErrorException();
$this->expectOutputString('');
$handler->render($request, $exception);
}
}
Loading…
Cancel
Save