diff options
author | msquare <msquare@notrademark.de> | 2017-11-28 15:43:51 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-28 15:43:51 +0100 |
commit | 599f2fd264bfc7b1b6826fe206442806e317340f (patch) | |
tree | 50cf84d7d07d11bd65b45c2c17f37632f6cd8eff /tests/Unit/Exceptions/Handlers | |
parent | a5fc5bd0979e8de1fce8a8addd351a6e7bd6aeb8 (diff) | |
parent | eda7f7788ea8012bd8be46405c56a666c11f3fa5 (diff) |
Merge pull request #365 from engelsystem/feature-igel-rewrite
Feature igel rewrite
Diffstat (limited to 'tests/Unit/Exceptions/Handlers')
-rw-r--r-- | tests/Unit/Exceptions/Handlers/LegacyDevelopmentTest.php | 35 | ||||
-rw-r--r-- | tests/Unit/Exceptions/Handlers/LegacyTest.php | 55 | ||||
-rw-r--r-- | tests/Unit/Exceptions/Handlers/WhoopsTest.php | 83 |
3 files changed, 173 insertions, 0 deletions
diff --git a/tests/Unit/Exceptions/Handlers/LegacyDevelopmentTest.php b/tests/Unit/Exceptions/Handlers/LegacyDevelopmentTest.php new file mode 100644 index 00000000..d5390c9e --- /dev/null +++ b/tests/Unit/Exceptions/Handlers/LegacyDevelopmentTest.php @@ -0,0 +1,35 @@ +<?php + +namespace Engelsystem\Test\Unit\Exceptions\handlers; + + +use Engelsystem\Exceptions\Handlers\LegacyDevelopment; +use Engelsystem\Http\Request; +use ErrorException; +use PHPUnit\Framework\TestCase; +use PHPUnit_Framework_MockObject_MockObject as Mock; + +class LegacyDevelopmentTest extends TestCase +{ + /** + * @covers \Engelsystem\Exceptions\Handlers\LegacyDevelopment::render() + * @covers \Engelsystem\Exceptions\Handlers\LegacyDevelopment::formatStackTrace() + */ + public function testRender() + { + $handler = new LegacyDevelopment(); + /** @var Request|Mock $request */ + $request = $this->createMock(Request::class); + $exception = new ErrorException('Lorem Ipsum', 4242, 1, 'foo.php', 9999); + + $regex = sprintf( + '%%<pre.*>.*ErrorException.*4242.*Lorem Ipsum.*%s.*%s.*%s.*</pre>%%is', + 'foo.php', + 9999, + __FUNCTION__ + ); + $this->expectOutputRegex($regex); + + $handler->render($request, $exception); + } +} 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); + } +} diff --git a/tests/Unit/Exceptions/Handlers/WhoopsTest.php b/tests/Unit/Exceptions/Handlers/WhoopsTest.php new file mode 100644 index 00000000..261ee83f --- /dev/null +++ b/tests/Unit/Exceptions/Handlers/WhoopsTest.php @@ -0,0 +1,83 @@ +<?php + +namespace Engelsystem\Test\Unit\Exceptions\handlers; + + +use Engelsystem\Application; +use Engelsystem\Exceptions\Handlers\Whoops; +use Engelsystem\Http\Request; +use Exception; +use PHPUnit\Framework\TestCase; +use PHPUnit_Framework_MockObject_MockObject as Mock; +use Whoops\Handler\JsonResponseHandler; +use Whoops\Handler\PrettyPageHandler; +use Whoops\Run as WhoopsRunner; +use Whoops\RunInterface as WhoopsRunnerInterface; + +class WhoopsTest extends TestCase +{ + /** + * @covers \Engelsystem\Exceptions\Handlers\Whoops + */ + public function testRender() + { + /** @var Application|Mock $app */ + $app = $this->createMock(Application::class); + /** @var Request|Mock $request */ + $request = $this->createMock(Request::class); + $request->expects($this->once()) + ->method('isXmlHttpRequest') + ->willReturn(true); + /** @var WhoopsRunnerInterface|Mock $whoopsRunner */ + $whoopsRunner = $this->getMockForAbstractClass(WhoopsRunnerInterface::class); + /** @var PrettyPageHandler|Mock $prettyPageHandler */ + $prettyPageHandler = $this->createMock(PrettyPageHandler::class); + $prettyPageHandler + ->expects($this->atLeastOnce()) + ->method('setApplicationPaths'); + $prettyPageHandler + ->expects($this->once()) + ->method('setApplicationPaths'); + $prettyPageHandler + ->expects($this->once()) + ->method('addDataTable'); + /** @var JsonResponseHandler|Mock $jsonResponseHandler */ + $jsonResponseHandler = $this->createMock(JsonResponseHandler::class); + $jsonResponseHandler->expects($this->once()) + ->method('setJsonApi') + ->with(true); + $jsonResponseHandler->expects($this->once()) + ->method('addTraceToOutput') + ->with(true); + /** @var Exception|Mock $exception */ + $exception = $this->createMock(Exception::class); + + $app->expects($this->exactly(3)) + ->method('make') + ->withConsecutive( + [WhoopsRunner::class], + [PrettyPageHandler::class], + [JsonResponseHandler::class] + ) + ->willReturnOnConsecutiveCalls( + $whoopsRunner, + $prettyPageHandler, + $jsonResponseHandler + ); + + $whoopsRunner + ->expects($this->exactly(2)) + ->method('pushHandler') + ->withConsecutive( + [$prettyPageHandler], + [$jsonResponseHandler] + ); + $whoopsRunner + ->expects($this->once()) + ->method('handleException') + ->with($exception); + + $handler = new Whoops($app); + $handler->render($request, $exception); + } +} |