diff options
author | Igor Scheller <igor.scheller@igorshp.de> | 2017-11-24 15:08:43 +0100 |
---|---|---|
committer | Igor Scheller <igor.scheller@igorshp.de> | 2017-11-25 11:27:38 +0100 |
commit | 25e434bce4986b48bd72729a55aa1096e5a76be3 (patch) | |
tree | b254fafaf789b4ebcc980fec8281675415706750 /tests/Unit/Exceptions/Handlers/LegacyTest.php | |
parent | 6eea072376cc9fd1034342a0e1d2173681268138 (diff) |
Refactored ExceptionHandler
Diffstat (limited to 'tests/Unit/Exceptions/Handlers/LegacyTest.php')
-rw-r--r-- | tests/Unit/Exceptions/Handlers/LegacyTest.php | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/Unit/Exceptions/Handlers/LegacyTest.php b/tests/Unit/Exceptions/Handlers/LegacyTest.php new file mode 100644 index 00000000..04b214f2 --- /dev/null +++ b/tests/Unit/Exceptions/Handlers/LegacyTest.php @@ -0,0 +1,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); + } +} |