2017-11-24 15:08:43 +01:00
|
|
|
<?php
|
|
|
|
|
2020-04-19 20:41:38 +02:00
|
|
|
namespace Engelsystem\Test\Unit\Exceptions\Handlers;
|
2017-11-24 15:08:43 +01:00
|
|
|
|
|
|
|
use Engelsystem\Exceptions\Handlers\Legacy;
|
|
|
|
use Engelsystem\Http\Request;
|
|
|
|
use Exception;
|
2019-04-24 10:45:00 +02:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2017-11-24 15:08:43 +01:00
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
class LegacyTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Exceptions\Handlers\Legacy::render()
|
|
|
|
*/
|
|
|
|
public function testRender()
|
|
|
|
{
|
|
|
|
$handler = new Legacy();
|
2019-04-24 10:45:00 +02:00
|
|
|
/** @var Request|MockObject $request */
|
2017-11-24 15:08:43 +01:00
|
|
|
$request = $this->createMock(Request::class);
|
2019-04-24 10:45:00 +02:00
|
|
|
/** @var Exception|MockObject $exception */
|
2017-11-24 15:08:43 +01:00
|
|
|
$exception = $this->createMock(Exception::class);
|
|
|
|
|
|
|
|
$this->expectOutputRegex('/.*error occurred.*/i');
|
|
|
|
|
|
|
|
$handler->render($request, $exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Exceptions\Handlers\Legacy::report()
|
|
|
|
* @covers \Engelsystem\Exceptions\Handlers\Legacy::stripBasePath()
|
|
|
|
*/
|
|
|
|
public function testReport()
|
|
|
|
{
|
|
|
|
$handler = new Legacy();
|
|
|
|
$exception = new Exception('Lorem Ipsum', 4242);
|
|
|
|
$line = __LINE__ - 1;
|
|
|
|
|
|
|
|
$log = tempnam(sys_get_temp_dir(), 'engelsystem-log');
|
|
|
|
$errorLog = ini_get('error_log');
|
|
|
|
ini_set('error_log', $log);
|
|
|
|
$handler->report($exception);
|
|
|
|
ini_set('error_log', $errorLog);
|
|
|
|
$logContent = file_get_contents($log);
|
|
|
|
unset($log);
|
|
|
|
|
2019-04-24 10:45:00 +02:00
|
|
|
$this->assertStringContainsString('4242', $logContent);
|
|
|
|
$this->assertStringContainsString('Lorem Ipsum', $logContent);
|
|
|
|
$this->assertStringContainsString(basename(__FILE__), $logContent);
|
|
|
|
$this->assertStringContainsString((string)$line, $logContent);
|
|
|
|
$this->assertStringContainsString(__FUNCTION__, $logContent);
|
|
|
|
$this->assertStringContainsString(json_encode(__CLASS__), $logContent);
|
2017-11-24 15:08:43 +01:00
|
|
|
}
|
|
|
|
}
|