Exception handling: Added NullHandler to be used in commands

This commit is contained in:
Igor Scheller 2020-05-11 23:20:28 +02:00 committed by msquare
parent 272be5eab2
commit 21ee2bd0d7
3 changed files with 48 additions and 0 deletions

View File

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

View File

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

View File

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