2017-11-24 15:08:43 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Engelsystem\Test\Unit\Exceptions\handlers;
|
|
|
|
|
|
|
|
|
|
|
|
use Engelsystem\Application;
|
|
|
|
use Engelsystem\Exceptions\Handlers\Whoops;
|
2018-10-08 19:30:37 +02:00
|
|
|
use Engelsystem\Helpers\Authenticator;
|
2017-11-24 15:08:43 +01:00
|
|
|
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);
|
2018-10-08 19:30:37 +02:00
|
|
|
/** @var Authenticator|Mock $auth */
|
|
|
|
$auth = $this->createMock(Authenticator::class);
|
2017-11-24 15:08:43 +01:00
|
|
|
/** @var Request|Mock $request */
|
|
|
|
$request = $this->createMock(Request::class);
|
|
|
|
/** @var WhoopsRunnerInterface|Mock $whoopsRunner */
|
|
|
|
$whoopsRunner = $this->getMockForAbstractClass(WhoopsRunnerInterface::class);
|
|
|
|
/** @var PrettyPageHandler|Mock $prettyPageHandler */
|
|
|
|
$prettyPageHandler = $this->createMock(PrettyPageHandler::class);
|
2018-10-08 19:30:37 +02:00
|
|
|
/** @var JsonResponseHandler|Mock $jsonResponseHandler */
|
|
|
|
$jsonResponseHandler = $this->createMock(JsonResponseHandler::class);
|
|
|
|
/** @var Exception|Mock $exception */
|
|
|
|
$exception = $this->createMock(Exception::class);
|
|
|
|
|
|
|
|
$request->expects($this->once())
|
|
|
|
->method('isXmlHttpRequest')
|
|
|
|
->willReturn(true);
|
|
|
|
|
2017-11-24 15:08:43 +01:00
|
|
|
$prettyPageHandler
|
|
|
|
->expects($this->atLeastOnce())
|
|
|
|
->method('setApplicationPaths');
|
|
|
|
$prettyPageHandler
|
|
|
|
->expects($this->once())
|
|
|
|
->method('setApplicationPaths');
|
|
|
|
$prettyPageHandler
|
|
|
|
->expects($this->once())
|
|
|
|
->method('addDataTable');
|
2018-10-08 19:30:37 +02:00
|
|
|
|
2017-11-24 15:08:43 +01:00
|
|
|
$jsonResponseHandler->expects($this->once())
|
|
|
|
->method('setJsonApi')
|
|
|
|
->with(true);
|
|
|
|
$jsonResponseHandler->expects($this->once())
|
|
|
|
->method('addTraceToOutput')
|
|
|
|
->with(true);
|
|
|
|
|
|
|
|
$app->expects($this->exactly(3))
|
|
|
|
->method('make')
|
|
|
|
->withConsecutive(
|
|
|
|
[WhoopsRunner::class],
|
|
|
|
[PrettyPageHandler::class],
|
|
|
|
[JsonResponseHandler::class]
|
|
|
|
)
|
|
|
|
->willReturnOnConsecutiveCalls(
|
|
|
|
$whoopsRunner,
|
|
|
|
$prettyPageHandler,
|
|
|
|
$jsonResponseHandler
|
|
|
|
);
|
2018-10-08 19:30:37 +02:00
|
|
|
$app->expects($this->once())
|
|
|
|
->method('has')
|
|
|
|
->with('authenticator')
|
|
|
|
->willReturn(true);
|
|
|
|
$app->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('authenticator')
|
|
|
|
->willReturn($auth);
|
|
|
|
|
|
|
|
$auth->expects($this->once())
|
|
|
|
->method('user')
|
|
|
|
->willReturn(null);
|
2017-11-24 15:08:43 +01:00
|
|
|
|
|
|
|
$whoopsRunner
|
|
|
|
->expects($this->exactly(2))
|
|
|
|
->method('pushHandler')
|
|
|
|
->withConsecutive(
|
|
|
|
[$prettyPageHandler],
|
|
|
|
[$jsonResponseHandler]
|
|
|
|
);
|
2018-08-07 03:06:21 +02:00
|
|
|
$whoopsRunner
|
|
|
|
->expects($this->once())
|
|
|
|
->method('writeToOutput')
|
|
|
|
->with(false);
|
|
|
|
$whoopsRunner
|
|
|
|
->expects($this->once())
|
|
|
|
->method('allowQuit')
|
|
|
|
->with(false);
|
2017-11-24 15:08:43 +01:00
|
|
|
$whoopsRunner
|
|
|
|
->expects($this->once())
|
|
|
|
->method('handleException')
|
|
|
|
->with($exception);
|
|
|
|
|
|
|
|
$handler = new Whoops($app);
|
|
|
|
$handler->render($request, $exception);
|
|
|
|
}
|
|
|
|
}
|