Skip to content

Commit

Permalink
require Symfony 4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
VasekPurchart committed Jun 21, 2018
1 parent 289537e commit 3945f9c
Show file tree
Hide file tree
Showing 11 changed files with 210 additions and 108 deletions.
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
],
"require": {
"php": "~7.1",
"symfony/config": "~3.3|~4.0",
"symfony/console": "~3.3|~4.0",
"symfony/dependency-injection": "~3.3|~4.0",
"symfony/http-kernel": "~3.3|~4.0",
"symfony/yaml": "~3.3|~4.0",
"symfony/config": "~4.0",
"symfony/console": "~4.0",
"symfony/dependency-injection": "~4.0",
"symfony/http-kernel": "~4.0",
"symfony/twig-bundle": "~4.0",
"symfony/yaml": "~4.0",
"tracy/tracy": "~2.4"
},
"require-dev": {
Expand Down
Binary file modified docs/tracy-in-console.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/tracy-with-profiler.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 12 additions & 16 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Usage

If you do not have any custom `kernel.exception` listeners this works out of the box. However if you have any, you have to ensure that they do not return any response, because that prevents the profiler from showing up (the same applies for the default Symfony exception screen).

If you need to change the default position of this listener (see order in `app/console debug:event-dispatcher`), use the configuration option `listener_priority`.
If you need to change the default position of this listener (see order in `bin/console debug:event-dispatcher`), use the configuration option `listener_priority`.

This bundle expects that you are using the default Symfony profiler screen rendered via the [TwigBundle](http://symfony.com/doc/current/reference/configuration/twig.html), which must be registered.

Expand All @@ -49,7 +49,7 @@ Configuration
Configuration structure with listed default values:
```yaml
# app/config/config.yml
# config/packages/tracy_blue_screen.yaml
tracy_blue_screen:
controller:
# Enable debug screen for controllers.
Expand Down Expand Up @@ -80,8 +80,8 @@ tracy_blue_screen:
# Add paths which should be collapsed (for external/compiled code) so that actual error is expanded.
collapse_paths:
# Defaults:
- %kernel.root_dir%/bootstrap.php.cache
- %kernel.cache_dir%
- '%kernel.root_dir%/bootstrap.php.cache'
- '%kernel.cache_dir%'
# plus paths set in BlueScreen instance used (/vendor)

```
Expand All @@ -91,12 +91,12 @@ You can also override services used internally, for example if you need to speci
```yaml
services:
my_blue_screen:
class: Tracy\BlueScreen
class: 'Tracy\BlueScreen'
properties:
info:
- 'environment: %kernel.environment%'

vasek_purchart.tracy_blue_screen.tracy.blue_screen: @my_blue_screen
vasek_purchart.tracy_blue_screen.tracy.blue_screen: '@my_blue_screen'
```
Installation
Expand All @@ -108,15 +108,11 @@ Install package [`vasek-purchart/tracy-blue-screen-bundle`](https://packagist.or
composer require vasek-purchart/tracy-blue-screen-bundle
```

Register the bundle in your application kernel:
Register the bundle in your application:
```php
// app/AppKernel.php
public function registerBundles()
{
return array(
// ...
new VasekPurchart\TracyBlueScreenBundle\TracyBlueScreenBundle(),
);
}
// config/bundles.php
return [
// ...
VasekPurchart\TracyBlueScreenBundle\TracyBlueScreenBundle::class => ['all' => true],
];
```

30 changes: 29 additions & 1 deletion src/DependencyInjection/TracyBlueScreenExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@

namespace VasekPurchart\TracyBlueScreenBundle\DependencyInjection;

use ReflectionClass;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use VasekPurchart\TracyBlueScreenBundle\TracyBlueScreenBundle;

class TracyBlueScreenExtension extends \Symfony\Component\HttpKernel\DependencyInjection\ConfigurableExtension
class TracyBlueScreenExtension
extends \Symfony\Component\HttpKernel\DependencyInjection\ConfigurableExtension
implements \Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface
{

public const CONTAINER_PARAMETER_BLUE_SCREEN_COLLAPSE_PATHS = 'vasek_purchart.tracy_blue_screen.blue_screen.collapse_paths';
Expand All @@ -17,6 +21,30 @@ class TracyBlueScreenExtension extends \Symfony\Component\HttpKernel\DependencyI
public const CONTAINER_PARAMETER_CONSOLE_LOG_DIRECTORY = 'vasek_purchart.tracy_blue_screen.console.log_directory';
public const CONTAINER_PARAMETER_CONTROLLER_LISTENER_PRIORITY = 'vasek_purchart.tracy_blue_screen.controller.listener_priority';

private const TWIG_BUNDLE_ALIAS = 'twig';
private const TWIG_TEMPLATES_NAMESPACE = 'Twig';

public function prepend(ContainerBuilder $container): void
{
if (!$container->hasExtension(self::TWIG_BUNDLE_ALIAS)) {
throw new \VasekPurchart\TracyBlueScreenBundle\DependencyInjection\TwigBundleRequiredException();
}

$container->loadFromExtension(self::TWIG_BUNDLE_ALIAS, [
'paths' => [
$this->getTemplatesDirectory() => self::TWIG_TEMPLATES_NAMESPACE,
],
]);
}

private function getTemplatesDirectory(): string
{
$bundleClassReflection = new ReflectionClass(TracyBlueScreenBundle::class);
$srcDirectoryPath = dirname($bundleClassReflection->getFileName());

return $srcDirectoryPath . '/Resources/views';
}

/**
* @param mixed[] $mergedConfig
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
Expand Down
15 changes: 15 additions & 0 deletions src/DependencyInjection/exceptions/TwigBundleRequiredException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types = 1);

namespace VasekPurchart\TracyBlueScreenBundle\DependencyInjection;

class TwigBundleRequiredException extends \Exception
{

public function __construct(?\Throwable $previous = null)
{
parent::__construct('TwigBundle must be registered for this bundle to work properly', 0, $previous);
}

}
5 changes: 0 additions & 5 deletions src/TracyBlueScreenBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,4 @@
class TracyBlueScreenBundle extends \Symfony\Component\HttpKernel\Bundle\Bundle
{

public function getParent(): string
{
return 'TwigBundle';
}

}
77 changes: 44 additions & 33 deletions tests/DependencyInjection/TracyBlueScreenExtensionConsoleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace VasekPurchart\TracyBlueScreenBundle\DependencyInjection;

use Symfony\Bundle\TwigBundle\DependencyInjection\TwigExtension;
use VasekPurchart\TracyBlueScreenBundle\BlueScreen\ConsoleBlueScreenErrorListener;

class TracyBlueScreenExtensionConsoleTest extends \Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase
Expand All @@ -13,10 +14,17 @@ public function setUp(): void
{
parent::setUp();
$this->setParameter('kernel.root_dir', __DIR__);
$this->setParameter('kernel.project_dir', __DIR__);
$this->setParameter('kernel.logs_dir', __DIR__ . '/tests-logs-dir');
$this->setParameter('kernel.cache_dir', __DIR__ . '/tests-cache-dir');
$this->setParameter('kernel.environment', 'dev');
$this->setParameter('kernel.debug', true);
$this->setParameter('kernel.bundles_metadata', [
'TwigBundle' => [
'namespace' => 'Symfony\\Bundle\\TwigBundle',
'path' => __DIR__,
],
]);
}

/**
Expand All @@ -26,40 +34,41 @@ protected function getContainerExtensions(): array
{
return [
new TracyBlueScreenExtension(),
new TwigExtension(),
];
}

public function testEnabledByDefault(): void
{
$this->load();
$this->loadExtensions();

$this->assertContainerBuilderHasService('vasek_purchart.tracy_blue_screen.blue_screen.console_blue_screen_error_listener', ConsoleBlueScreenErrorListener::class);
$this->assertContainerBuilderHasServiceDefinitionWithTag('vasek_purchart.tracy_blue_screen.blue_screen.console_blue_screen_error_listener', 'kernel.event_listener', [
'event' => 'console.error',
'priority' => '%' . TracyBlueScreenExtension::CONTAINER_PARAMETER_CONSOLE_LISTENER_PRIORITY . '%',
]);

$this->compile();
}

public function testDisabled(): void
{
$this->load([
'console' => [
'enabled' => false,
$this->loadExtensions([
'tracy_blue_screen' => [
'console' => [
'enabled' => false,
],
],
]);

$this->assertContainerBuilderNotHasService('vasek_purchart.tracy_blue_screen.blue_screen.console_blue_screen_error_listener');

$this->compile();
}

public function testEnabled(): void
{
$this->load([
'console' => [
'enabled' => true,
$this->loadExtensions([
'tracy_blue_screen' => [
'console' => [
'enabled' => true,
],
],
]);

Expand All @@ -68,65 +77,67 @@ public function testEnabled(): void
'event' => 'console.error',
'priority' => '%' . TracyBlueScreenExtension::CONTAINER_PARAMETER_CONSOLE_LISTENER_PRIORITY . '%',
]);

$this->compile();
}

public function testDefaultLogsDirIsKernelLogsDir(): void
{
$this->load();
$this->loadExtensions();

$this->assertContainerBuilderHasParameter(TracyBlueScreenExtension::CONTAINER_PARAMETER_CONSOLE_LOG_DIRECTORY, __DIR__ . '/tests-logs-dir');

$this->compile();
}

public function testCustomLogsDir(): void
{
$this->load([
'console' => [
'log_directory' => __DIR__ . '/foobar',
$this->loadExtensions([
'tracy_blue_screen' => [
'console' => [
'log_directory' => __DIR__ . '/foobar',
],
],
]);

$this->assertContainerBuilderHasParameter(TracyBlueScreenExtension::CONTAINER_PARAMETER_CONSOLE_LOG_DIRECTORY, __DIR__ . '/foobar');

$this->compile();
}

public function testDefaultBrowserIsNull(): void
{
$this->load();
$this->loadExtensions();

$this->assertContainerBuilderHasParameter(TracyBlueScreenExtension::CONTAINER_PARAMETER_CONSOLE_BROWSER, null);

$this->compile();
}

public function testCustomBrowser(): void
{
$this->load([
'console' => [
'browser' => 'google-chrome',
$this->loadExtensions([
'tracy_blue_screen' => [
'console' => [
'browser' => 'google-chrome',
],
],
]);

$this->assertContainerBuilderHasParameter(TracyBlueScreenExtension::CONTAINER_PARAMETER_CONSOLE_BROWSER, 'google-chrome');

$this->compile();
}

public function testConfigureListenerPriority(): void
{
$this->load([
'console' => [
'listener_priority' => 123,
$this->loadExtensions([
'tracy_blue_screen' => [
'console' => [
'listener_priority' => 123,
],
],
]);

$this->assertContainerBuilderHasParameter(TracyBlueScreenExtension::CONTAINER_PARAMETER_CONSOLE_LISTENER_PRIORITY, 123);
}

$this->compile();
/**
* @param mixed[] $configuration format: extensionAlias(string) => configuration(mixed[])
*/
private function loadExtensions(array $configuration = []): void
{
TracyBlueScreenExtensionTest::loadExtensionsToContainer($this->container, $configuration, $this->getMinimalConfiguration());
}

}
Loading

0 comments on commit 3945f9c

Please sign in to comment.