Skip to content

Commit d81cfde

Browse files
Merge branch '11.5'
2 parents 6f0cdaf + 71215c7 commit d81cfde

File tree

6 files changed

+103
-33
lines changed

6 files changed

+103
-33
lines changed

src/Runner/PHPT/PhptTestCase.php

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ private function shouldTestBeSkipped(array $sections, array $settings): bool
434434

435435
$skipIfCode = $this->render($sections['SKIPIF']);
436436

437-
if ($this->shouldRunSkipIfInSubprocess($sections, $skipIfCode)) {
437+
if ($this->shouldRunInSubprocess($sections, $skipIfCode)) {
438438
$jobResult = JobRunnerRegistry::run(
439439
new Job(
440440
$skipIfCode,
@@ -471,7 +471,7 @@ private function shouldTestBeSkipped(array $sections, array $settings): bool
471471
/**
472472
* @param array<non-empty-string, non-empty-string> $sections
473473
*/
474-
private function shouldRunCleanInSubprocess(array $sections, string $cleanCode): bool
474+
private function shouldRunInSubprocess(array $sections, string $cleanCode): bool
475475
{
476476
if (isset($sections['INI'])) {
477477
// to get per-test INI settings, we need a dedicated subprocess
@@ -488,7 +488,7 @@ private function shouldRunCleanInSubprocess(array $sections, string $cleanCode):
488488
foreach ($sideEffects as $sideEffect) {
489489
if (
490490
$sideEffect === SideEffect::STANDARD_OUTPUT || // stdout is fine, we will catch it using output-buffering
491-
$sideEffect === SideEffect::INPUT_OUTPUT // IO is fine while cleanup, as it doesn't pollute the main process
491+
$sideEffect === SideEffect::INPUT_OUTPUT // IO is fine, as it doesn't pollute the main process
492492
) {
493493
continue;
494494
}
@@ -499,35 +499,6 @@ private function shouldRunCleanInSubprocess(array $sections, string $cleanCode):
499499
return false;
500500
}
501501

502-
/**
503-
* @param array<non-empty-string, non-empty-string> $sections
504-
*/
505-
private function shouldRunSkipIfInSubprocess(array $sections, string $skipIfCode): bool
506-
{
507-
if (isset($sections['INI'])) {
508-
// to get per-test INI settings, we need a dedicated subprocess
509-
return true;
510-
}
511-
512-
$detector = new SideEffectsDetector;
513-
$sideEffects = $detector->getSideEffects($skipIfCode);
514-
515-
if ($sideEffects === []) {
516-
return false; // no side-effects
517-
}
518-
519-
foreach ($sideEffects as $sideEffect) {
520-
if ($sideEffect === SideEffect::STANDARD_OUTPUT) {
521-
// stdout is fine, we will catch it using output-buffering
522-
continue;
523-
}
524-
525-
return true;
526-
}
527-
528-
return false;
529-
}
530-
531502
private function runCodeInLocalSandbox(string $code): string
532503
{
533504
$code = preg_replace('/^<\?(?:php)?|\?>\s*+$/', '', $code);
@@ -552,7 +523,7 @@ private function runClean(array $sections, bool $collectCoverage): void
552523

553524
$cleanCode = $this->render($sections['CLEAN']);
554525

555-
if ($this->shouldRunCleanInSubprocess($sections, $cleanCode)) {
526+
if ($this->shouldRunInSubprocess($sections, $cleanCode)) {
556527
$result = JobRunnerRegistry::run(
557528
new Job(
558529
$cleanCode,
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
PHPT skip condition with IO operations run in main process
3+
--SKIPIF--
4+
<?php declare(strict_types=1);
5+
file_put_contents(__DIR__ . '/skipif-io.log', 'some content');
6+
unlink(__DIR__ . '/skipif-io.log');
7+
--FILE--
8+
<?php declare(strict_types=1);
9+
echo "Hello, World!\n";
10+
--EXPECT--
11+
Hello, World!
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--TEST--
2+
PHPT skip condition with require() runs in subprocess
3+
--SKIPIF--
4+
<?php declare(strict_types=1);
5+
require (__DIR__ . '/phpt-skipif-required-file.php');
6+
--FILE--
7+
<?php declare(strict_types=1);
8+
echo "Hello, World!\n";
9+
--EXPECT--
10+
Hello, World!
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace PhpTSkipIfRequiredFile;
11+
12+
class SomeClass
13+
{
14+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
The right events are emitted in the right order for PHPT test using IO in skipif
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--do-not-cache-result';
6+
$_SERVER['argv'][] = '--no-configuration';
7+
$_SERVER['argv'][] = '--debug';
8+
$_SERVER['argv'][] = __DIR__ . '/../_files/phpt-skipif-io.phpt';
9+
10+
require __DIR__ . '/../../bootstrap.php';
11+
12+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
13+
--EXPECTF--
14+
PHPUnit Started (PHPUnit %s using %s)
15+
Test Runner Configured
16+
Event Facade Sealed
17+
Test Suite Loaded (1 test)
18+
Test Runner Started
19+
Test Suite Sorted
20+
Test Runner Execution Started (1 test)
21+
Test Suite Started (%s%ephpt-skipif-io.phpt, 1 test)
22+
Test Preparation Started (%s%ephpt-skipif-io.phpt)
23+
Test Prepared (%s%ephpt-skipif-io.phpt)
24+
Child Process Started
25+
Child Process Finished
26+
Test Passed (%s%ephpt-skipif-io.phpt)
27+
Test Finished (%s%ephpt-skipif-io.phpt)
28+
Test Suite Finished (%s%ephpt-skipif-io.phpt, 1 test)
29+
Test Runner Execution Finished
30+
Test Runner Finished
31+
PHPUnit Finished (Shell Exit Code: 0)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
The right events are emitted in the right order for PHPT test using require() in skipif
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--do-not-cache-result';
6+
$_SERVER['argv'][] = '--no-configuration';
7+
$_SERVER['argv'][] = '--debug';
8+
$_SERVER['argv'][] = __DIR__ . '/../_files/phpt-skipif-require.phpt';
9+
10+
require __DIR__ . '/../../bootstrap.php';
11+
12+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
13+
--EXPECTF--
14+
PHPUnit Started (PHPUnit %s using %s)
15+
Test Runner Configured
16+
Event Facade Sealed
17+
Test Suite Loaded (1 test)
18+
Test Runner Started
19+
Test Suite Sorted
20+
Test Runner Execution Started (1 test)
21+
Test Suite Started (%s%ephpt-skipif-require.phpt, 1 test)
22+
Test Preparation Started (%s%ephpt-skipif-require.phpt)
23+
Test Prepared (%s%ephpt-skipif-require.phpt)
24+
Child Process Started
25+
Child Process Finished
26+
Child Process Started
27+
Child Process Finished
28+
Test Passed (%s%ephpt-skipif-require.phpt)
29+
Test Finished (%s%ephpt-skipif-require.phpt)
30+
Test Suite Finished (%s%ephpt-skipif-require.phpt, 1 test)
31+
Test Runner Execution Finished
32+
Test Runner Finished
33+
PHPUnit Finished (Shell Exit Code: 0)

0 commit comments

Comments
 (0)