summaryrefslogtreecommitdiff
path: root/tests/Unit/Exceptions/Handlers/WhoopsTest.php
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2017-11-24 15:08:43 +0100
committerIgor Scheller <igor.scheller@igorshp.de>2017-11-25 11:27:38 +0100
commit25e434bce4986b48bd72729a55aa1096e5a76be3 (patch)
treeb254fafaf789b4ebcc980fec8281675415706750 /tests/Unit/Exceptions/Handlers/WhoopsTest.php
parent6eea072376cc9fd1034342a0e1d2173681268138 (diff)
Refactored ExceptionHandler
Diffstat (limited to 'tests/Unit/Exceptions/Handlers/WhoopsTest.php')
-rw-r--r--tests/Unit/Exceptions/Handlers/WhoopsTest.php83
1 files changed, 83 insertions, 0 deletions
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);
+ }
+}