Skip to content

Commit 94ce455

Browse files
feature #16502 [Bridge\PhpUnit] Add extra clock-mocked namespaces in phpunit.xml.dist (nicolas-grekas)
This PR was merged into the 2.8 branch. Discussion ---------- [Bridge\PhpUnit] Add extra clock-mocked namespaces in phpunit.xml.dist | Q | A | ------------- | --- | Bug fix? | yes | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - This fixes the currently failing tests on travis by: - checking for class existence before checking for groups, recursively now, when loading `@group time-sensitive` annotations - allow specifying extra clock-mocked namespaces in phpunit.xml files, required e.g. when HttpKernel is tested standalone and requires clock-mocks to be enabled for the HttpFoundation namespace. Commits ------- cd36c07 [Bridge\PhpUnit] Add extra clock-mocked namespaces in phpunit.xml.dist
2 parents 515007e + cd36c07 commit 94ce455

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,26 @@
2020
*/
2121
class SymfonyTestsListener extends \PHPUnit_Framework_BaseTestListener
2222
{
23+
private static $globallyEnabled = false;
2324
private $state = -1;
2425
private $skippedFile = false;
2526
private $wasSkipped = array();
2627
private $isSkipped = array();
2728

29+
public function __construct(array $extraClockMockedNamespaces = array())
30+
{
31+
if ($extraClockMockedNamespaces) {
32+
foreach ($extraClockMockedNamespaces as $ns) {
33+
ClockMock::register($ns.'\DummyClass');
34+
}
35+
}
36+
if (self::$globallyEnabled) {
37+
$this->state = -2;
38+
} else {
39+
self::$globallyEnabled = true;
40+
}
41+
}
42+
2843
public function __destruct()
2944
{
3045
if (0 < $this->state) {
@@ -56,9 +71,16 @@ public function startTestSuite(\PHPUnit_Framework_TestSuite $suite)
5671
}
5772
}
5873
}
59-
foreach ($suite->tests() as $test) {
60-
if ($test instanceof \PHPUnit_Framework_TestSuite && in_array('time-sensitive', \PHPUnit_Util_Test::getGroups($test->getName()), true)) {
61-
ClockMock::register($test->getName());
74+
$testSuites = array($suite);
75+
for ($i = 0; isset($testSuites[$i]); ++$i) {
76+
foreach ($testSuites[$i]->tests() as $test) {
77+
if ($test instanceof \PHPUnit_Framework_TestSuite) {
78+
if (class_exists($test->getName(), false) && in_array('time-sensitive', \PHPUnit_Util_Test::getGroups($test->getName()), true)) {
79+
ClockMock::register($test->getName());
80+
} else {
81+
$testSuites[] = $test;
82+
}
83+
}
6284
}
6385
}
6486
} elseif (2 === $this->state) {
@@ -91,7 +113,7 @@ public function addSkippedTest(\PHPUnit_Framework_Test $test, \Exception $e, $ti
91113

92114
public function startTest(\PHPUnit_Framework_Test $test)
93115
{
94-
if ($test instanceof \PHPUnit_Framework_TestCase) {
116+
if (-2 < $this->state && $test instanceof \PHPUnit_Framework_TestCase) {
95117
$groups = \PHPUnit_Util_Test::getGroups(get_class($test), $test->getName());
96118

97119
if (in_array('time-sensitive', $groups, true)) {
@@ -103,7 +125,7 @@ public function startTest(\PHPUnit_Framework_Test $test)
103125

104126
public function endTest(\PHPUnit_Framework_Test $test, $time)
105127
{
106-
if ($test instanceof \PHPUnit_Framework_TestCase) {
128+
if (-2 < $this->state && $test instanceof \PHPUnit_Framework_TestCase) {
107129
$groups = \PHPUnit_Util_Test::getGroups(get_class($test), $test->getName());
108130

109131
if (in_array('time-sensitive', $groups, true)) {

src/Symfony/Component/HttpKernel/phpunit.xml.dist

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,14 @@
2525
</exclude>
2626
</whitelist>
2727
</filter>
28+
29+
<listeners>
30+
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener">
31+
<arguments>
32+
<array>
33+
<element><string>Symfony\Component\HttpFoundation</string></element>
34+
</array>
35+
</arguments>
36+
</listener>
37+
</listeners>
2838
</phpunit>

0 commit comments

Comments
 (0)
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