From cd36c076295000ac7b06b8dd16d5c3720fdea995 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 9 Nov 2015 11:00:06 +0100 Subject: [PATCH] [Bridge\PhpUnit] Add extra clock-mocked namespaces in phpunit.xml.dist --- .../Bridge/PhpUnit/SymfonyTestsListener.php | 32 ++++++++++++++++--- .../Component/HttpKernel/phpunit.xml.dist | 10 ++++++ 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php b/src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php index 4dd52d4e7705b..4f4dc78508c22 100644 --- a/src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php +++ b/src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php @@ -20,11 +20,26 @@ */ class SymfonyTestsListener extends \PHPUnit_Framework_BaseTestListener { + private static $globallyEnabled = false; private $state = -1; private $skippedFile = false; private $wasSkipped = array(); private $isSkipped = array(); + public function __construct(array $extraClockMockedNamespaces = array()) + { + if ($extraClockMockedNamespaces) { + foreach ($extraClockMockedNamespaces as $ns) { + ClockMock::register($ns.'\DummyClass'); + } + } + if (self::$globallyEnabled) { + $this->state = -2; + } else { + self::$globallyEnabled = true; + } + } + public function __destruct() { if (0 < $this->state) { @@ -56,9 +71,16 @@ public function startTestSuite(\PHPUnit_Framework_TestSuite $suite) } } } - foreach ($suite->tests() as $test) { - if ($test instanceof \PHPUnit_Framework_TestSuite && in_array('time-sensitive', \PHPUnit_Util_Test::getGroups($test->getName()), true)) { - ClockMock::register($test->getName()); + $testSuites = array($suite); + for ($i = 0; isset($testSuites[$i]); ++$i) { + foreach ($testSuites[$i]->tests() as $test) { + if ($test instanceof \PHPUnit_Framework_TestSuite) { + if (class_exists($test->getName(), false) && in_array('time-sensitive', \PHPUnit_Util_Test::getGroups($test->getName()), true)) { + ClockMock::register($test->getName()); + } else { + $testSuites[] = $test; + } + } } } } elseif (2 === $this->state) { @@ -91,7 +113,7 @@ public function addSkippedTest(\PHPUnit_Framework_Test $test, \Exception $e, $ti public function startTest(\PHPUnit_Framework_Test $test) { - if ($test instanceof \PHPUnit_Framework_TestCase) { + if (-2 < $this->state && $test instanceof \PHPUnit_Framework_TestCase) { $groups = \PHPUnit_Util_Test::getGroups(get_class($test), $test->getName()); if (in_array('time-sensitive', $groups, true)) { @@ -103,7 +125,7 @@ public function startTest(\PHPUnit_Framework_Test $test) public function endTest(\PHPUnit_Framework_Test $test, $time) { - if ($test instanceof \PHPUnit_Framework_TestCase) { + if (-2 < $this->state && $test instanceof \PHPUnit_Framework_TestCase) { $groups = \PHPUnit_Util_Test::getGroups(get_class($test), $test->getName()); if (in_array('time-sensitive', $groups, true)) { diff --git a/src/Symfony/Component/HttpKernel/phpunit.xml.dist b/src/Symfony/Component/HttpKernel/phpunit.xml.dist index 13149663e488a..17c48935c7158 100644 --- a/src/Symfony/Component/HttpKernel/phpunit.xml.dist +++ b/src/Symfony/Component/HttpKernel/phpunit.xml.dist @@ -25,4 +25,14 @@ + + + + + + Symfony\Component\HttpFoundation + + + + pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy