Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
bug #21825 [PhpUnitBridge] disable global test listener when not regi…
…stered (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
-------

e068661 disable global test listener when not registered
  • Loading branch information
fabpot committed Mar 2, 2017
2 parents 4b27628 + e068661 commit cadc313
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php
Expand Up @@ -68,6 +68,12 @@ public function __destruct()
}
}

public function globalListenerDisabled()
{
self::$globallyEnabled = false;
$this->state = -1;
}

public function startTestSuite(\PHPUnit_Framework_TestSuite $suite)
{
$suiteName = $suite->getName();
Expand Down
12 changes: 11 additions & 1 deletion src/Symfony/Bridge/PhpUnit/TextUI/TestRunner.php
Expand Up @@ -33,7 +33,17 @@ protected function handleConfiguration(array &$arguments)

$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;
}

Expand Down

0 comments on commit cadc313

Please sign in to comment.