|
|
@ -4,14 +4,16 @@ namespace Engelsystem\Test\Unit\Exceptions\Handlers;
|
|
|
|
|
|
|
|
|
|
|
|
use Engelsystem\Exceptions\Handlers\Legacy;
|
|
|
|
use Engelsystem\Exceptions\Handlers\Legacy;
|
|
|
|
use Engelsystem\Http\Request;
|
|
|
|
use Engelsystem\Http\Request;
|
|
|
|
|
|
|
|
use ErrorException;
|
|
|
|
use Exception;
|
|
|
|
use Exception;
|
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
use Psr\Log\Test\TestLogger;
|
|
|
|
|
|
|
|
|
|
|
|
class LegacyTest extends TestCase
|
|
|
|
class LegacyTest extends TestCase
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Exceptions\Handlers\Legacy::render()
|
|
|
|
* @covers \Engelsystem\Exceptions\Handlers\Legacy::render
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function testRender()
|
|
|
|
public function testRender()
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -27,22 +29,36 @@ class LegacyTest extends TestCase
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Exceptions\Handlers\Legacy::report()
|
|
|
|
* @covers \Engelsystem\Exceptions\Handlers\Legacy::report
|
|
|
|
* @covers \Engelsystem\Exceptions\Handlers\Legacy::stripBasePath()
|
|
|
|
* @covers \Engelsystem\Exceptions\Handlers\Legacy::setLogger
|
|
|
|
|
|
|
|
* @covers \Engelsystem\Exceptions\Handlers\Legacy::stripBasePath
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function testReport()
|
|
|
|
public function testReport()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$handler = new Legacy();
|
|
|
|
$handler = new Legacy();
|
|
|
|
$exception = new Exception('Lorem Ipsum', 4242);
|
|
|
|
$exception = new Exception('Lorem Ipsum', 4242);
|
|
|
|
$line = __LINE__ - 1;
|
|
|
|
$line = __LINE__ - 1;
|
|
|
|
|
|
|
|
$exception2 = new Exception('Test Exception');
|
|
|
|
|
|
|
|
$exception3 = new Exception('Mor Exceptions!');
|
|
|
|
|
|
|
|
$logger = new TestLogger();
|
|
|
|
|
|
|
|
$logger2 = $this->createMock(TestLogger::class);
|
|
|
|
|
|
|
|
$logger2->expects($this->once())
|
|
|
|
|
|
|
|
->method('critical')
|
|
|
|
|
|
|
|
->willReturnCallback(function () {
|
|
|
|
|
|
|
|
throw new ErrorException();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$log = tempnam(sys_get_temp_dir(), 'engelsystem-log');
|
|
|
|
$logfile = tempnam(sys_get_temp_dir(), 'engelsystem-log');
|
|
|
|
$errorLog = ini_get('error_log');
|
|
|
|
$errorLog = ini_get('error_log');
|
|
|
|
ini_set('error_log', $log);
|
|
|
|
ini_set('error_log', $logfile);
|
|
|
|
$handler->report($exception);
|
|
|
|
$handler->report($exception);
|
|
|
|
|
|
|
|
$handler->setLogger($logger);
|
|
|
|
|
|
|
|
$handler->report($exception2);
|
|
|
|
|
|
|
|
$handler->setLogger($logger2);
|
|
|
|
|
|
|
|
$handler->report($exception3);
|
|
|
|
ini_set('error_log', $errorLog);
|
|
|
|
ini_set('error_log', $errorLog);
|
|
|
|
$logContent = file_get_contents($log);
|
|
|
|
$logContent = file_get_contents($logfile);
|
|
|
|
unset($log);
|
|
|
|
unset($logfile);
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertStringContainsString('4242', $logContent);
|
|
|
|
$this->assertStringContainsString('4242', $logContent);
|
|
|
|
$this->assertStringContainsString('Lorem Ipsum', $logContent);
|
|
|
|
$this->assertStringContainsString('Lorem Ipsum', $logContent);
|
|
|
@ -50,5 +66,10 @@ class LegacyTest extends TestCase
|
|
|
|
$this->assertStringContainsString((string)$line, $logContent);
|
|
|
|
$this->assertStringContainsString((string)$line, $logContent);
|
|
|
|
$this->assertStringContainsString(__FUNCTION__, $logContent);
|
|
|
|
$this->assertStringContainsString(__FUNCTION__, $logContent);
|
|
|
|
$this->assertStringContainsString(json_encode(__CLASS__), $logContent);
|
|
|
|
$this->assertStringContainsString(json_encode(__CLASS__), $logContent);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertTrue($logger->hasRecordThatPasses(function (array $record) use ($exception2) {
|
|
|
|
|
|
|
|
$context = $record['context'];
|
|
|
|
|
|
|
|
return isset($context['exception']) && $context['exception'] === $exception2;
|
|
|
|
|
|
|
|
}, 'critical'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|