Skip to content

Commit

Permalink
show exception
Browse files Browse the repository at this point in the history
  • Loading branch information
recca0120 committed Jul 3, 2018
1 parent 3454c86 commit 3279e3e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 31 deletions.
1 change: 1 addition & 0 deletions config/tracy.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
return [
'enabled' => env('APP_DEBUG') === true,
'showBar' => env('APP_ENV') !== 'production',
'showException' => true,
'route' => [
'prefix' => 'tracy',
'as' => 'tracy.',
Expand Down
11 changes: 10 additions & 1 deletion src/LaravelTracyServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,19 @@ public function boot(Kernel $kernel, View $view, Router $router)

$config = $this->app['config']['tracy'];
$enabled = Arr::get($config, 'enabled', true) === true;
if ($enabled === true) {
if ($enabled === false) {
return;
}

$showException = Arr::get($config, 'showException', true);
if ($showException === true) {
$this->app->extend(ExceptionHandler::class, function ($exceptionHandler, $app) {
return new Handler($exceptionHandler, $app[DebuggerManager::class]);
});
}

$showBar = Arr::get($config, 'showBar', true);
if ($showBar === true) {
$this->handleRoutes($router, Arr::get($config, 'route', []));
$kernel->prependMiddleware(RenderBar::class);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Middleware/RenderBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ protected function render($request, $next)
*/
protected function reject(Response $response, Request $request, $ajax)
{
if ($this->debuggerManager->showBar() === false ||
if (
$response instanceof BinaryFileResponse ||
$response instanceof StreamedResponse ||
$response instanceof RedirectResponse
Expand Down
29 changes: 0 additions & 29 deletions tests/Middleware/RenderBarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,6 @@ public function testHandleAssets()
$this->assertSame($response, $renderBar->handle($request, $next));
}

public function testHandleShowBarIsFalse()
{
$renderBar = new RenderBar(
$debuggerManager = m::mock('Recca0120\LaravelTracy\DebuggerManager'),
$events = m::mock('Illuminate\Contracts\Events\Dispatcher')
);

$request = m::mock('Illuminate\Http\Request');
$response = m::mock('Symfony\Component\HttpFoundation\Response');
$next = function (Request $request) use ($response) {
return $response;
};

$request->shouldReceive('has')->once()->with('_tracy_bar')->andReturn(false);
$request->shouldReceive('ajax')->once()->andReturn(false);
$debuggerManager->shouldReceive('dispatch')->once();
$debuggerManager->shouldReceive('showBar')->once()->andReturn(false);

$this->assertSame($response, $renderBar->handle($request, $next));
}

public function testHandleBinaryFileResponse()
{
$renderBar = new RenderBar(
Expand All @@ -73,7 +52,6 @@ public function testHandleBinaryFileResponse()
$request->shouldReceive('has')->once()->with('_tracy_bar')->andReturn(false);
$request->shouldReceive('ajax')->once()->andReturn(false);
$debuggerManager->shouldReceive('dispatch')->once();
$debuggerManager->shouldReceive('showBar')->once()->andReturn(true);

$this->assertSame($response, $renderBar->handle($request, $next));
}
Expand All @@ -94,7 +72,6 @@ public function testHandleStreamedResponse()
$request->shouldReceive('has')->once()->with('_tracy_bar')->andReturn(false);
$request->shouldReceive('ajax')->once()->andReturn(false);
$debuggerManager->shouldReceive('dispatch')->once();
$debuggerManager->shouldReceive('showBar')->once()->andReturn(true);

$this->assertSame($response, $renderBar->handle($request, $next));
}
Expand All @@ -115,7 +92,6 @@ public function testHandleRedirectResponse()
$request->shouldReceive('has')->once()->with('_tracy_bar')->andReturn(false);
$request->shouldReceive('ajax')->once()->andReturn(false);
$debuggerManager->shouldReceive('dispatch')->once();
$debuggerManager->shouldReceive('showBar')->once()->andReturn(true);

$this->assertSame($response, $renderBar->handle($request, $next));
}
Expand All @@ -136,7 +112,6 @@ public function testHandleElse()

$request->shouldReceive('has')->once()->with('_tracy_bar')->andReturn(false);
$debuggerManager->shouldReceive('dispatch')->once();
$debuggerManager->shouldReceive('showBar')->once()->andReturn(true);
$request->shouldReceive('ajax')->once()->andReturn(false);
$headers->shouldReceive('get')->once()->with('Content-Type')->andReturn($contentType = '');
$debuggerManager->shouldReceive('accepts')->once()->andReturn($accepts = ['text/html']);
Expand All @@ -161,7 +136,6 @@ public function testHandleAjax()

$request->shouldReceive('has')->once()->with('_tracy_bar')->andReturn(false);
$debuggerManager->shouldReceive('dispatch')->once();
$debuggerManager->shouldReceive('showBar')->once()->andReturn(true);
$request->shouldReceive('ajax')->once()->andReturn($ajax = true);

$events->shouldReceive('fire')->once()->with(m::type('Recca0120\LaravelTracy\Events\BeforeBarRender'));
Expand Down Expand Up @@ -189,7 +163,6 @@ public function testHandleStatusCodeBiggerThan400()

$request->shouldReceive('has')->once()->with('_tracy_bar')->andReturn(false);
$debuggerManager->shouldReceive('dispatch')->once();
$debuggerManager->shouldReceive('showBar')->once()->andReturn(true);
$request->shouldReceive('ajax')->once()->andReturn($ajax = false);

$headers->shouldReceive('get')->once()->with('Content-Type')->andReturn($contentType = '');
Expand Down Expand Up @@ -221,7 +194,6 @@ public function testHandleEmptyAccepts()

$request->shouldReceive('has')->once()->with('_tracy_bar')->andReturn(false);
$debuggerManager->shouldReceive('dispatch')->once();
$debuggerManager->shouldReceive('showBar')->once()->andReturn(true);
$request->shouldReceive('ajax')->once()->andReturn($ajax = false);

$headers->shouldReceive('get')->once()->with('Content-Type')->andReturn($contentType = '');
Expand Down Expand Up @@ -253,7 +225,6 @@ public function testHandleAcceptContentType()

$request->shouldReceive('has')->once()->with('_tracy_bar')->andReturn(false);
$debuggerManager->shouldReceive('dispatch')->once();
$debuggerManager->shouldReceive('showBar')->once()->andReturn(true);
$request->shouldReceive('ajax')->once()->andReturn($ajax = false);

$headers->shouldReceive('get')->once()->with('Content-Type')->andReturn($contentType = 'text/html');
Expand Down

0 comments on commit 3279e3e

Please sign in to comment.