Skip to content

Commit

Permalink
Fixes (#17)
Browse files Browse the repository at this point in the history
Fix php errors
  • Loading branch information
snapshotpl committed Oct 25, 2016
1 parent 0783ef8 commit 771cb2d
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 10 deletions.
10 changes: 6 additions & 4 deletions config/zfsnapphpdebugbar.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
'php-debug-bar' => [
'view' => [
'custom-style-path' => 'zf-snap-php-debug-bar.css',
'debugbar-resources' => __DIR__.'/../../../maximebf/debugbar/src/DebugBar/Resources/',
'custom-resources' => __DIR__.'/../assets/',
],
'enabled' => true,
'auto-append-assets' => true,
Expand All @@ -26,8 +28,8 @@
],
],
'controllers' => [
'invokables' => [
ZfSnapPhpDebugBar\Controller\Resources::class => ZfSnapPhpDebugBar\Controller\Resources::class,
'factories' => [
ZfSnapPhpDebugBar\Controller\Resources::class => ZfSnapPhpDebugBar\Controller\ResourcesFactory::class,
],
],
'view_helpers' => [
Expand All @@ -51,8 +53,8 @@
'phpdebugbar-custom-resource' => [
'type' => 'regex',
'options' => [
'regex' => '/ZfSnapPhpDebugBar/Resources/(?<resource>[a-zA-Z0-9_.\-/]+)',
'spec' => '/ZfSnapPhpDebugBar/Resources/%resource%',
'regex' => '/zfsnapphpdebugbar/resources/(?<resource>[a-zA-Z0-9_.\-/]+)',
'spec' => '/zfsnapphpdebugbar/resources/%resource%',
'defaults' => [
'controller' => ZfSnapPhpDebugBar\Controller\Resources::class,
'action' => 'custom',
Expand Down
13 changes: 11 additions & 2 deletions src/Controller/Resources.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,23 @@ class Resources extends AbstractActionController
'js' => 'text/javascript; charset=UTF-8',
];

private $debugbarResourcesPath;
private $customResourcesPath;

public function __construct($debugbarResourcesPath, $customResourcesPath)
{
$this->debugbarResourcesPath = $debugbarResourcesPath;
$this->customResourcesPath = $customResourcesPath;
}

public function indexAction()
{
return $this->prepareAssetResponse(__DIR__.'/../../../../../maximebf/debugbar/src/DebugBar/Resources/');
return $this->prepareAssetResponse($this->debugbarResourcesPath);
}

public function customAction()
{
return $this->prepareAssetResponse(__DIR__.'/../../../assets/');
return $this->prepareAssetResponse($this->customResourcesPath);
}

protected function prepareAssetResponse($path)
Expand Down
20 changes: 20 additions & 0 deletions src/Controller/ResourcesFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace ZfSnapPhpDebugBar\Controller;

use Interop\Container\ContainerInterface;
use Zend\ServiceManager\ServiceLocatorAwareInterface;

final class ResourcesFactory
{
public function __invoke(ContainerInterface $container)
{
if ($container instanceof ServiceLocatorAwareInterface) {
$container = $container->getServiceLocator();
}

$config = $container->get('config')['php-debug-bar']['view'];

return new Resources($config['debugbar-resources'], $config['custom-resources']);
}
}
3 changes: 1 addition & 2 deletions src/Listener/RenderOnShutdownListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public function renderOnShutdown(MvcEvent $event)
return;
}

$renderer = $debugbar->getJavascriptRenderer();
$renderer->renderOnShutdown(false);
$this->javascriptRenderer->renderOnShutdown(false);
}
}
2 changes: 1 addition & 1 deletion src/Log/Writer/PhpDebugBarFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function createService(ServiceLocatorInterface $serviceLocator)
/**
* @return PhpDebugBar
*/
public function __invoke(ContainerInterface $container, $requestedName, mixed $options = null)
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
/* @var $debugbar DebugBar */
$debugbar = $container->get('debugbar');
Expand Down
31 changes: 30 additions & 1 deletion tests/Functional/DebugBarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/
class DebugBarTest extends AbstractHttpControllerTestCase
{

protected function setUp()
{
$this->traceError = false;
Expand Down Expand Up @@ -66,6 +65,36 @@ public function testContainExceptionMessage()
$this->assertResponseContains(DummyController::EXCEPTION_MESSAGE);
}

public function testContainsUriToDebugBarResource()
{
$this->dispatch('/');

$this->assertResponseContains('/DebugBar/Resources/debugbar.js');
}

public function testContainsUriToCustomResource()
{
$this->dispatch('/');

$this->assertResponseContains('/zfsnapphpdebugbar/resources/zf-snap-php-debug-bar.css');
}

public function testGetStaticResourceFromDebugBar()
{
$this->dispatch('/DebugBar/Resources/debugbar.js');

$this->assertResponseStatusCode(200);
$this->assertResponseHeaderContains('Content-Type', 'text/javascript; charset=UTF-8');
}

public function testGetStaticCustomResource()
{
$this->dispatch('/zfsnapphpdebugbar/resources/zf-snap-php-debug-bar.css');

$this->assertResponseStatusCode(200);
$this->assertResponseHeaderContains('Content-Type', 'text/css; charset=UTF-8');
}

private function assertResponseContains($string)
{
$this->assertContains($string, $this->getResponse()->getContent());
Expand Down
3 changes: 3 additions & 0 deletions tests/assets/global.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
'php-debug-bar' => [
'auto-append-assets' => true,
'render-on-shutdown' => false,
'view' => [
'debugbar-resources' => __DIR__.'/../../vendor/maximebf/debugbar/src/DebugBar/Resources/',
],
],
'router' => [
'routes' => [
Expand Down

0 comments on commit 771cb2d

Please sign in to comment.