blob: 04b214f2e2c75ce782bfce03026e6b5ae51b2795 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
<?php
namespace Engelsystem\Test\Unit\Exceptions\handlers;
use Engelsystem\Exceptions\Handlers\Legacy;
use Engelsystem\Http\Request;
use Exception;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_MockObject_MockObject as Mock;
class LegacyTest extends TestCase
{
/**
* @covers \Engelsystem\Exceptions\Handlers\Legacy::render()
*/
public function testRender()
{
$handler = new Legacy();
/** @var Request|Mock $request */
$request = $this->createMock(Request::class);
/** @var Exception|Mock $exception */
$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);
$this->assertContains('4242', $logContent);
$this->assertContains('Lorem Ipsum', $logContent);
$this->assertContains(basename(__FILE__), $logContent);
$this->assertContains((string)$line, $logContent);
$this->assertContains(__FUNCTION__, $logContent);
$this->assertContains(json_encode(__CLASS__), $logContent);
}
}
|