From 2fb11fce28e7b7f37c73e0d47415f30700552e14 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sun, 9 Sep 2018 00:22:19 +0200 Subject: [PATCH] [PhpUnitBridge] enable DebugClassLoader by default --- .../PhpUnit/Legacy/SymfonyTestsListenerTrait.php | 9 +++++++++ .../Compiler/AbstractRecursivePass.php | 16 ++++++++++++++-- .../Compiler/AnalyzeServiceReferencesPass.php | 3 ++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php b/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php index d072e7e91ffa..b527e039662b 100644 --- a/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php +++ b/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php @@ -18,6 +18,7 @@ use PHPUnit\Util\Blacklist; use Symfony\Bridge\PhpUnit\ClockMock; use Symfony\Bridge\PhpUnit\DnsMock; +use Symfony\Component\Debug\DebugClassLoader; /** * PHP 5.3 compatible trait-like shared implementation. @@ -52,6 +53,8 @@ public function __construct(array $mockedNamespaces = array()) Blacklist::$blacklistedClassNames['\Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait'] = 2; } + $enableDebugClassLoader = \class_exists('Symfony\Component\Debug\DebugClassLoader'); + foreach ($mockedNamespaces as $type => $namespaces) { if (!\is_array($namespaces)) { $namespaces = array($namespaces); @@ -66,6 +69,12 @@ public function __construct(array $mockedNamespaces = array()) DnsMock::register($ns.'\DummyClass'); } } + if ('debug-class-loader' === $type) { + $enableDebugClassLoader = $namespaces && $namespaces[0]; + } + } + if ($enableDebugClassLoader) { + DebugClassLoader::enable(); } if (self::$globallyEnabled) { $this->state = -2; diff --git a/src/Symfony/Component/DependencyInjection/Compiler/AbstractRecursivePass.php b/src/Symfony/Component/DependencyInjection/Compiler/AbstractRecursivePass.php index 9d543c0634b4..8d6ea6b37c3f 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/AbstractRecursivePass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/AbstractRecursivePass.php @@ -32,6 +32,7 @@ abstract class AbstractRecursivePass implements CompilerPassInterface private $processExpressions = false; private $expressionLanguage; + private $inExpression = false; /** * {@inheritdoc} @@ -52,12 +53,21 @@ protected function enableExpressionProcessing() $this->processExpressions = true; } + protected function inExpression(bool $reset = true): bool + { + $inExpression = $this->inExpression; + if ($reset) { + $this->inExpression = false; + } + + return $inExpression; + } + /** * Processes a value found in a definition tree. * * @param mixed $value * @param bool $isRoot - * @param bool $inExpression * * @return mixed The processed value */ @@ -194,7 +204,9 @@ private function getExpressionLanguage() $this->expressionLanguage = new ExpressionLanguage(null, $providers, function ($arg) { if ('""' === substr_replace($arg, '', 1, -1)) { $id = stripcslashes(substr($arg, 1, -1)); - $arg = $this->processValue(new Reference($id), false, true); + $this->inExpression = true; + $arg = $this->processValue(new Reference($id)); + $this->inExpression = false; if (!$arg instanceof Reference) { throw new RuntimeException(sprintf('"%s::processValue()" must return a Reference when processing an expression, %s returned for service("%s").', \get_class($this), \is_object($arg) ? \get_class($arg) : \gettype($arg))); } diff --git a/src/Symfony/Component/DependencyInjection/Compiler/AnalyzeServiceReferencesPass.php b/src/Symfony/Component/DependencyInjection/Compiler/AnalyzeServiceReferencesPass.php index 2000d3611bc5..7522cab7c630 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/AnalyzeServiceReferencesPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/AnalyzeServiceReferencesPass.php @@ -79,9 +79,10 @@ public function process(ContainerBuilder $container) } } - protected function processValue($value, $isRoot = false, bool $inExpression = false) + protected function processValue($value, $isRoot = false) { $lazy = $this->lazy; + $inExpression = $this->inExpression(); if ($value instanceof ArgumentInterface) { $this->lazy = true;