Skip to content

Commit

Permalink
feature #28412 [PhpUnitBridge] enable DebugClassLoader by default (ni…
Browse files Browse the repository at this point in the history
…colas-grekas)

This PR was merged into the 4.2-dev branch.

Discussion
----------

[PhpUnitBridge] enable DebugClassLoader by default

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | symfony/symfony-docs#10360

With this PR, the phpunit-bridge will enable `DebugClassLoader` by default, making it do its job: throw deprecation notices at autoloading time. On top of #28329, this made me spot some glitches in the code base, fixed here also.

This can be disabled by configuring the listener in `phpunit.xml.dist` files, adding `<element key="debug-class-loader"><integer>0</integer></element>` next to `<element key="time-sensitive">...`.

Commits
-------

2fb11fc [PhpUnitBridge] enable DebugClassLoader by default
  • Loading branch information
nicolas-grekas committed Sep 18, 2018
2 parents 3caa9d4 + 2fb11fc commit 680f319
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down
Expand Up @@ -32,6 +32,7 @@ abstract class AbstractRecursivePass implements CompilerPassInterface

private $processExpressions = false;
private $expressionLanguage;
private $inExpression = false;

/**
* {@inheritdoc}
Expand All @@ -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
*/
Expand Down Expand Up @@ -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)));
}
Expand Down
Expand Up @@ -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;
Expand Down

0 comments on commit 680f319

Please sign in to comment.