Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Commit

Permalink
Issue 490 (#513)
Browse files Browse the repository at this point in the history
working on #490 part 1
  • Loading branch information
prisis authored and Daniel Bannert committed May 22, 2017
1 parent 702ea3c commit d1b15e2
Show file tree
Hide file tree
Showing 189 changed files with 3,659 additions and 2,792 deletions.
26 changes: 12 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"php" : "^7.1",
"ext-fileinfo" : "*",
"ext-openssl" : "*",
"cache/array-adapter" : "^0.4",
"cache/void-adapter" : "^0.3",
"cache/array-adapter" : "^0.5",
"cache/void-adapter" : "^0.4",
"cakephp/chronos" : "^1.0",
"container-interop/container-interop" : "^1.1",
"container-interop/service-provider" : "^0.3",
Expand All @@ -56,6 +56,9 @@
"opis/closure" : "^2.2",
"paragonie/password_lock" : "^3.0",
"php-di/invoker" : "^2.0",
"psr/cache" : "^1.0",
"psr/log" : "^1.0",
"psr/simple-cache" : "^1.0",
"respect/validation" : "^1.1",
"symfony/console" : "^3.2",
"symfony/debug" : "^3.2",
Expand Down Expand Up @@ -106,10 +109,9 @@
},
"require-dev": {
"aws/aws-sdk-php" : "^3.18",
"cache/filesystem-adapter" : "^0.3",
"cache/filesystem-adapter" : "^0.4",
"cache/namespaced-cache" : "^0.1",
"cache/session-handler" : "^0.2",
"cache/void-adapter" : "^0.3",
"erusev/parsedown-extra" : "^0.7",
"filp/whoops" : "^2.0",
"guzzlehttp/guzzle" : "^6.0",
Expand All @@ -136,9 +138,9 @@
"twig/twig" : "^2.0",
"sepia/po-parser" : "^4.2",
"spatie/flysystem-dropbox" : "^1.0",
"symfony/routing" : "^3.1",
"symfony/routing" : "^3.2",
"symfony/var-dumper" : "^3.2",
"symfony/yaml" : "^3.1",
"symfony/yaml" : "^3.2",
"yosymfony/toml" : "^0.3"
},
"autoload": {
Expand All @@ -160,17 +162,13 @@
"suggest": {
"alcaeus/mongo-php-adapter" : "Required to use the ext-mongo interface on ext-mongodb interface (^1.0).",
"aws/aws-sdk-php" : "Required to use the SQS queue driver and SES mail driver (^3.18).",
"cache/apc-adapter" : "Required to use the Apc cache (^0.3).",
"cache/apcu-adapter" : "Required to use the Apcu cache (^0.3).",
"cache/array-adapter" : "Required to use the Array cache (^0.2)",
"cache/filesystem-adapter" : "Required to use the Filesystem cache (^0.3).",
"cache/filesystem-adapter" : "Required to use the Filesystem cache (^0.4).",
"cache/memcache-adapter" : "Required to use the Memcache cache (^0.3).",
"cache/memcached-adapter" : "Required to use the Memcached cache (^0.3).",
"cache/memcached-adapter" : "Required to use the Memcached cache (^0.4).",
"cache/namespaced-adapter" : "Required to use the Namespaced cache (^0.1).",
"cache/mongodb-adapter" : "Required to use the Mongodb cache (^0.2).",
"cache/predis-adapter" : "Required to use the Predis cache (^0.4).",
"cache/mongodb-adapter" : "Required to use the Mongodb cache (^0.3).",
"cache/predis-adapter" : "Required to use the Predis cache (^0.5).",
"cache/session-handler" : "Required to use the Session cache (^0.1).",
"cache/void-adapter" : "Required to use the Void cache (^0.3).",
"guzzlehttp/guzzle" : "Required to use the Mailgun and Mandrill mail drivers and the ping methods on schedules (^6.0).",
"league/flysystem-aws-s3-v3" : "Required to use the Flysystem S3 adapter (^1.0).",
"league/flysystem-cached-adapter" : "Required to use the Flysystem Caching adapter (^1.0.3).",
Expand Down
4 changes: 3 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ parameters:
- '#\$casters of method Symfony\\Component\\VarDumper\\Cloner\\AbstractCloner::addCasters#'
- '#Call to function count\(\) with argument type iterable\(mixed\[\]\) will always result in number 1#'
- '#Method Viserio\\Component\\Filesystem\\Encryption\\EncryptionWrapper::decryptStream() should return resource but returns mixed|string#'
- '#set\(\) has invalid typehint type Psr\\SimpleCache\\DateInterval#'
- '#setMultiple\(\) has invalid typehint type Psr\\SimpleCache\\DateInterval#'

# DUMP_COMMA_SEPARATOR constant only supported from var-dumper v3.3
- "#DUMP_COMMA_SEPARATOR#"
Expand Down Expand Up @@ -109,7 +111,7 @@ parameters:
- '#Method Viserio\\Component\\Cookie\\AbstractCookieCollector::forget#'

# Wrapper
- '#Viserio\\Component\\WebProfiler\\DataCollectors\\Bridge\\PDO\\TraceablePDODecorater::__construct#'
- '#Viserio\\Component\\Profiler\\DataCollectors\\Bridge\\PDO\\TraceablePDODecorater::__construct#'

# Ignore missing container property for ConfigurationTrait
- '#Access to an undefined property Viserio\\Component\\Exception\\Displayers\\HtmlDisplayer::\$container#'
Expand Down
4 changes: 2 additions & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@
<testsuite name="Narrowspark View Component Test Suite">
<directory>./src/Viserio/Component/View/Tests</directory>
</testsuite>
<testsuite name="Narrowspark WebProfiler Component Test Suite">
<directory>./src/Viserio/Component/WebProfiler/Tests</directory>
<testsuite name="Narrowspark Profiler Component Test Suite">
<directory>./src/Viserio/Component/Profiler/Tests</directory>
</testsuite>
</testsuites>

Expand Down
22 changes: 11 additions & 11 deletions src/Viserio/Bridge/Twig/DataCollector/Resources/css/twig.css
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
.webprofiler-panel.webprofiler-panel-twig-data-collector.active .twig-graph {
margin-top: 25px;
.profiler-panel.profiler-panel-twig-data-collector.active .twig-graph {
margin: 25px 0;
}
.webprofiler-panel.webprofiler-panel-twig-data-collector.active .twig-graph pre {
.profiler-panel.profiler-panel-twig-data-collector.active .twig-graph pre {
font-size: 14px;
color: #2B2A28;
color: var(--profiler-second-font-color);
padding: 10px;
background-color: #fff;
background-color: #FFF;
}
.webprofiler-panel.webprofiler-panel-twig-data-collector.active .twig-graph pre .status-success {
color: #4F805D;
.profiler-panel.profiler-panel-twig-data-collector.active .twig-graph pre .status-success {
color: var(--profiler-status-green-color);
}
.webprofiler-panel.webprofiler-panel-twig-data-collector.active .twig-graph pre .status-warning {
background-color: #A46A1F;
.profiler-panel.profiler-panel-twig-data-collector.active .twig-graph pre .status-warning {
background-color: var(--profiler-status-yellow-color);
color: #FFF;
padding: 0px 5px;
}
.webprofiler-panel.webprofiler-panel-twig-data-collector.active .twig-graph pre .status-error {
color: #B0413E;
.profiler-panel.profiler-panel-twig-data-collector.active .twig-graph pre .status-error {
color: var(--profiler-status-red-color);
}
8 changes: 4 additions & 4 deletions src/Viserio/Bridge/Twig/DataCollector/TwigDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
use Twig_Markup;
use Twig_Profiler_Dumper_Html;
use Twig_Profiler_Profile;
use Viserio\Component\Contracts\WebProfiler\AssetAware as AssetAwareContract;
use Viserio\Component\Contracts\WebProfiler\PanelAware as PanelAwareContract;
use Viserio\Component\Contracts\WebProfiler\TooltipAware as TooltipAwareContract;
use Viserio\Component\WebProfiler\DataCollectors\AbstractDataCollector;
use Viserio\Component\Contracts\Profiler\AssetAware as AssetAwareContract;
use Viserio\Component\Contracts\Profiler\PanelAware as PanelAwareContract;
use Viserio\Component\Contracts\Profiler\TooltipAware as TooltipAwareContract;
use Viserio\Component\Profiler\DataCollectors\AbstractDataCollector;

class TwigDataCollector extends AbstractDataCollector implements
PanelAwareContract,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Viserio\Bridge\Twig\DataCollector\TwigDataCollector;
use Viserio\Component\Contracts\OptionsResolver\RequiresComponentConfig as RequiresComponentConfigContract;
use Viserio\Component\Contracts\OptionsResolver\RequiresMandatoryOptions as RequiresMandatoryOptionsContract;
use Viserio\Component\Contracts\WebProfiler\WebProfiler as WebProfilerContract;
use Viserio\Component\Contracts\Profiler\Profiler as ProfilerContract;
use Viserio\Component\OptionsResolver\OptionsResolver;

class TwigBridgeDataCollectorsServiceProvider implements
Expand All @@ -35,7 +35,7 @@ public function getServices()
return new Twig_Profiler_Profile();
},
TwigEnvironment::class => [self::class, 'createTwigEnvironment'],
WebProfilerContract::class => [self::class, 'createProfiler'],
ProfilerContract::class => [self::class, 'createProfiler'],
];
}

Expand All @@ -44,7 +44,7 @@ public function getServices()
*/
public function getDimensions(): iterable
{
return ['viserio', 'webprofiler'];
return ['viserio', 'profiler'];
}

/**
Expand All @@ -65,9 +65,9 @@ public function getMandatoryOptions(): iterable
* @param \Interop\Container\ContainerInterface $container
* @param null|callable $getPrevious
*
* @return null|\Viserio\Component\Contracts\WebProfiler\WebProfiler
* @return null|\Viserio\Component\Contracts\Profiler\Profiler
*/
public static function createProfiler(ContainerInterface $container, ?callable $getPrevious = null): ?WebProfilerContract
public static function createProfiler(ContainerInterface $container, ?callable $getPrevious = null): ?ProfilerContract
{
if ($getPrevious !== null) {
self::resolveOptions($container);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Interop\Container\ContainerInterface;
use Interop\Container\ServiceProvider;
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Twig_Environment as TwigEnvironment;
use Twig_Lexer;
use Twig_Loader_Array;
Expand Down Expand Up @@ -129,7 +130,7 @@ public static function createTwigEnvironment(ContainerInterface $container): Twi
$twig->setLexer($container->get(Twig_Lexer::class));
}

if ($options['debug']) {
if ($options['debug'] && class_exists(VarCloner::class)) {
$twig->addExtension(new DumpExtension());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ public function testGetMenuAndPosition()
{
$collect = $this->getTwigDataCollector();

static::assertSame(
self::assertSame(
[
'icon' => file_get_contents(__DIR__ . '/../../DataCollector/Resources/icons/ic_view_quilt_white_24px.svg'),
'label' => 'Twig',
'value' => '',
],
$collect->getMenu()
);
static::assertSame('left', $collect->getMenuPosition());
self::assertSame('left', $collect->getMenuPosition());
}

public function testGetTooltip()
Expand All @@ -36,36 +36,14 @@ public function testGetTooltip()
$this->mock(ResponseInterface::class)
);

static::assertSame('<div class="webprofiler-menu-tooltip-group"><div class="webprofiler-menu-tooltip-group-piece"><b>Template calls</b><span>1</span></div><div class="webprofiler-menu-tooltip-group-piece"><b>Block calls</b><span>0</span></div><div class="webprofiler-menu-tooltip-group-piece"><b>Macro calls</b><span>0</span></div></div>', $collect->getTooltip());
}

public function testGetPanel()
{
$profile = new Twig_Profiler_Profile();
$env = new Twig_Environment(
new Twig_Loader_Array(['test.twig' => 'test'])
);
$env->addExtension(new Twig_Extension_Profiler($profile));

$template = $env->load('test.twig');
$template->render([]);

$collect = new TwigDataCollector($profile, $env);
$collect->collect(
$this->mock(ServerRequestInterface::class),
$this->mock(ResponseInterface::class)
);

$expect = preg_replace('/(\r\n|\n\r|\r)/', "\n", '<div class="webprofiler-tabs row"><div class="webprofiler-tabs-tab col span_6"><input type="radio" name="tabgroup" id="tab-0-58a60028922b9"><label for="tab-0-58a60028922b9">Twig <span class="counter">1</span></label><div class="webprofiler-tabs-tab-content"><h3>Twig Metrics</h3><ul class="metrics"><li class="metric"><span class="value">' . $this->formatDuration($collect->getTime()) . '</span><span class="label">Render time</span></li><li class="metric"><span class="value">1</span><span class="label">Template calls</span></li><li class="metric"><span class="value">0</span><span class="label">Block calls</span></li><li class="metric"><span class="value">0</span><span class="label">Macro calls</span></li></ul><h3>Rendered Templates</h3><table class="row"><thead><tr><th scope="col" class="Template Name">Template Name</th><th scope="col" class="Render Count">Render Count</th></tr></thead><tbody><tr><th>test.twig</th><td>1</td></tr></tbody></table><div class="twig-graph"><h3>Rendering Call Graph</h3>' . $collect->getHtmlCallGraph() . '</div></div></div><div class="webprofiler-tabs-tab col span_6"><input type="radio" name="tabgroup" id="tab-1-58a60028922c0"><label for="tab-1-58a60028922c0">Twig Extensions <span class="counter">4</span></label><div class="webprofiler-tabs-tab-content"><table class="row"><thead><tr><th scope="col" class="Extension">Extension</th></tr></thead><tbody><tr><td>Twig_Extension_Core</td></tr><tr><td>Twig_Extension_Escaper</td></tr><tr><td>Twig_Extension_Optimizer</td></tr><tr><td>Twig_Extension_Profiler</td></tr></tbody></table></div></div></div>');

static::assertSame($this->removeTabId($expect), $this->removeTabId(preg_replace('/(\r\n|\n\r|\r)/', "\n", $collect->getPanel())));
self::assertSame('<div class="profiler-menu-tooltip-group"><div class="profiler-menu-tooltip-group-piece"><b>Template calls</b><span>1</span></div><div class="profiler-menu-tooltip-group-piece"><b>Block calls</b><span>0</span></div><div class="profiler-menu-tooltip-group-piece"><b>Macro calls</b><span>0</span></div></div>', $collect->getTooltip());
}

public function testGetProfile()
{
$collect = $this->getTwigDataCollector();

static::assertInstanceOf(Twig_Profiler_Profile::class, $collect->getProfile());
self::assertInstanceOf(Twig_Profiler_Profile::class, $collect->getProfile());
}

private function removeTabId(string $html): string
Expand Down
4 changes: 2 additions & 2 deletions src/Viserio/Bridge/Twig/Tests/Engine/TwigEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function testGet()

$template = $engine->get(['name' => 'twightml.twig.html']);

static::assertSame(trim('<!DOCTYPE html>
self::assertSame(trim('<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
Expand Down Expand Up @@ -110,7 +110,7 @@ public function testAddTwigExtensions()

$template = $engine->get(['name' => 'twightml2.twig.html']);

static::assertSame(trim('<!DOCTYPE html>
self::assertSame(trim('<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
use Viserio\Bridge\Twig\Providers\TwigBridgeDataCollectorsServiceProvider;
use Viserio\Bridge\Twig\Providers\TwigBridgeServiceProvider;
use Viserio\Component\Container\Container;
use Viserio\Component\Contracts\WebProfiler\WebProfiler as WebProfilerContract;
use Viserio\Component\Contracts\Profiler\Profiler as ProfilerContract;
use Viserio\Component\Filesystem\Providers\FilesServiceProvider;
use Viserio\Component\HttpFactory\Providers\HttpFactoryServiceProvider;
use Viserio\Component\OptionsResolver\Providers\OptionsResolverServiceProvider;
use Viserio\Component\Profiler\Providers\ProfilerServiceProvider;
use Viserio\Component\View\Providers\ViewServiceProvider;
use Viserio\Component\WebProfiler\Providers\WebProfilerServiceProvider;

/**
* @runTestsInSeparateProcesses
Expand All @@ -29,13 +29,13 @@ public function testGetServices()
$container->register(new FilesServiceProvider());
$container->register(new ViewServiceProvider());
$container->register(new HttpFactoryServiceProvider());
$container->register(new WebProfilerServiceProvider());
$container->register(new ProfilerServiceProvider());
$container->register(new TwigBridgeServiceProvider());
$container->register(new TwigBridgeDataCollectorsServiceProvider());

$container->instance('config', [
'viserio' => [
'webprofiler' => [
'profiler' => [
'enable' => true,
'collector' => [
'twig' => true,
Expand All @@ -61,13 +61,13 @@ public function testGetServices()
],
]);

$profiler = $container->get(WebProfilerContract::class);
$profiler = $container->get(ProfilerContract::class);

static::assertInstanceOf(WebProfilerContract::class, $profiler);
self::assertInstanceOf(ProfilerContract::class, $profiler);

static::assertTrue(array_key_exists('time-data-collector', $profiler->getCollectors()));
static::assertTrue(array_key_exists('memory-data-collector', $profiler->getCollectors()));
static::assertTrue(array_key_exists('twig-data-collector', $profiler->getCollectors()));
self::assertTrue(array_key_exists('time-data-collector', $profiler->getCollectors()));
self::assertTrue(array_key_exists('memory-data-collector', $profiler->getCollectors()));
self::assertTrue(array_key_exists('twig-data-collector', $profiler->getCollectors()));

self::assertInstanceOf(Twig_Profiler_Profile::class, $container->get(Twig_Profiler_Profile::class));
self::assertInstanceOf(Twig_Environment::class, $container->get(Twig_Environment::class));
Expand Down
2 changes: 1 addition & 1 deletion src/Viserio/Bridge/Twig/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"viserio/session" : "self.version",
"viserio/support" : "self.version",
"viserio/translation" : "self.version",
"viserio/web-profiler" : "self.version"
"viserio/profiler" : "self.version"
},
"autoload": {
"psr-4": {
Expand Down
Loading

0 comments on commit d1b15e2

Please sign in to comment.