bug #21825 [PhpUnitBridge] disable global test listener when not registered (xabbuh)

This PR was merged into the 2.8 branch.

Discussion
----------

[PhpUnitBridge] disable global test listener when not registered

| Q             | A
| ------------- | ---
| Branch?       | 2.8
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

The global test listener is always initialized to register the clock
mock and DNS mock as soon as possible. However, when the listener is
registered locally through the PHPUnit config, it will never be
registered as a listener. In thise case, the state of the local
listener must be reset to correctly report expected deprecation test
results.

Commits
-------

e068661240 disable global test listener when not registered
This commit is contained in:
Fabien Potencier 2017-03-01 17:45:34 -08:00
commit cadc31330e
2 changed files with 17 additions and 1 deletions

View File

@ -68,6 +68,12 @@ class SymfonyTestsListener extends \PHPUnit_Framework_BaseTestListener
}
}
public function globalListenerDisabled()
{
self::$globallyEnabled = false;
$this->state = -1;
}
public function startTestSuite(\PHPUnit_Framework_TestSuite $suite)
{
$suiteName = $suite->getName();

View File

@ -33,7 +33,17 @@ class TestRunner extends \PHPUnit_TextUI_TestRunner
$arguments['listeners'] = isset($arguments['listeners']) ? $arguments['listeners'] : array();
if (!array_filter($arguments['listeners'], function ($listener) { return $listener instanceof SymfonyTestsListener; })) {
$registeredLocally = false;
foreach ($arguments['listeners'] as $registeredListener) {
if ($registeredListener instanceof SymfonyTestsListener) {
$registeredListener->globalListenerDisabled();
$registeredLocally = true;
break;
}
}
if (!$registeredLocally) {
$arguments['listeners'][] = $listener;
}