Skip to content

Commit b94cb85

Browse files
bug #38971 [PhpUnitBridge] fix replaying skipped tests (nicolas-grekas)
This PR was merged into the 4.4 branch. Discussion ---------- [PhpUnitBridge] fix replaying skipped tests | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Spotted while working on symfony/polyfill#310 See also https://3v4l.org/D6Gro for the newly skipped tests in symfony/intl Commits ------- 849d1b3845 [PhpUnitBridge] fix replaying skipped tests
2 parents 444ab45 + ae1f0fd commit b94cb85

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

Legacy/SymfonyTestsListenerTrait.php

+17-18
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function startTestSuite($suite)
121121
$suiteName = $suite->getName();
122122

123123
foreach ($suite->tests() as $test) {
124-
if (!($test instanceof \PHPUnit\Framework\TestCase || $test instanceof TestCase)) {
124+
if (!($test instanceof \PHPUnit_Framework_TestCase || $test instanceof TestCase)) {
125125
continue;
126126
}
127127
if (null === Test::getPreserveGlobalStateSettings(\get_class($test), $test->getName(false))) {
@@ -156,7 +156,7 @@ public function startTestSuite($suite)
156156
$testSuites = [$suite];
157157
for ($i = 0; isset($testSuites[$i]); ++$i) {
158158
foreach ($testSuites[$i]->tests() as $test) {
159-
if ($test instanceof TestSuite) {
159+
if ($test instanceof \PHPUnit_Framework_TestSuite || $test instanceof TestSuite) {
160160
if (!class_exists($test->getName(), false)) {
161161
$testSuites[] = $test;
162162
continue;
@@ -172,12 +172,19 @@ public function startTestSuite($suite)
172172
}
173173
}
174174
} elseif (2 === $this->state) {
175+
$suites = [$suite];
175176
$skipped = [];
176-
foreach ($suite->tests() as $test) {
177-
if (!($test instanceof \PHPUnit\Framework\TestCase || $test instanceof TestCase)
178-
|| isset($this->wasSkipped[$suiteName]['*'])
179-
|| isset($this->wasSkipped[$suiteName][$test->getName()])) {
180-
$skipped[] = $test;
177+
while ($s = array_shift($suites)) {
178+
foreach ($s->tests() as $test) {
179+
if ($test instanceof \PHPUnit_Framework_TestSuite || $test instanceof TestSuite) {
180+
$suites[] = $test;
181+
continue
182+
}
183+
if (($test instanceof \PHPUnit_Framework_TestCase || $test instanceof TestCase)
184+
&& isset($this->wasSkipped[\get_class($test)][$test->getName()])
185+
) {
186+
$skipped[] = $test;
187+
}
181188
}
182189
}
183190
$suite->setTests($skipped);
@@ -187,21 +194,13 @@ public function startTestSuite($suite)
187194
public function addSkippedTest($test, \Exception $e, $time)
188195
{
189196
if (0 < $this->state) {
190-
if ($test instanceof \PHPUnit\Framework\TestCase || $test instanceof TestCase) {
191-
$class = \get_class($test);
192-
$method = $test->getName();
193-
} else {
194-
$class = $test->getName();
195-
$method = '*';
196-
}
197-
198-
$this->isSkipped[$class][$method] = 1;
197+
$this->isSkipped[\get_class($test)][$test->getName()] = 1;
199198
}
200199
}
201200

202201
public function startTest($test)
203202
{
204-
if (-2 < $this->state && ($test instanceof \PHPUnit\Framework\TestCase || $test instanceof TestCase)) {
203+
if (-2 < $this->state && ($test instanceof \PHPUnit_Framework_TestCase || $test instanceof TestCase)) {
205204
// This event is triggered before the test is re-run in isolation
206205
if ($this->willBeIsolated($test)) {
207206
$this->runsInSeparateProcess = tempnam(sys_get_temp_dir(), 'deprec');
@@ -291,7 +290,7 @@ public function endTest($test, $time)
291290
$this->expectedDeprecations = $this->gatheredDeprecations = [];
292291
$this->previousErrorHandler = null;
293292
}
294-
if (!$this->runsInSeparateProcess && -2 < $this->state && ($test instanceof \PHPUnit\Framework\TestCase || $test instanceof TestCase)) {
293+
if (!$this->runsInSeparateProcess && -2 < $this->state && ($test instanceof \PHPUnit_Framework_TestCase || $test instanceof TestCase)) {
295294
if (\in_array('time-sensitive', $groups, true)) {
296295
ClockMock::withClockMock(false);
297296
}

0 commit comments

Comments
 (0)