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
-------

2fb11fce28 [PhpUnitBridge] enable DebugClassLoader by default
  • Loading branch information
nicolas-grekas committed Sep 18, 2018
2 parents 42db479 + cda2b5b commit c54c44f
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Legacy/SymfonyTestsListenerTrait.php
Original file line number Diff line number Diff line change
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

0 comments on commit c54c44f

Please sign in to comment.