Skip to content

Commit 03f0973

Browse files
staabmsebastianbergmann
authored andcommitted
Avoid subprocess when SKIPIF triggers IO
1 parent befe10b commit 03f0973

File tree

3 files changed

+45
-32
lines changed

3 files changed

+45
-32
lines changed

src/Runner/PHPT/PhptTestCase.php

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ private function shouldTestBeSkipped(array $sections, array $settings): bool
432432

433433
$skipIfCode = $this->render($sections['SKIPIF']);
434434

435-
if ($this->shouldRunSkipIfInSubprocess($sections, $skipIfCode)) {
435+
if ($this->shouldRunInSubprocess($sections, $skipIfCode)) {
436436
$jobResult = JobRunnerRegistry::run(
437437
new Job(
438438
$skipIfCode,
@@ -469,7 +469,7 @@ private function shouldTestBeSkipped(array $sections, array $settings): bool
469469
/**
470470
* @param array<non-empty-string, non-empty-string> $sections
471471
*/
472-
private function shouldRunCleanInSubprocess(array $sections, string $cleanCode): bool
472+
private function shouldRunInSubprocess(array $sections, string $cleanCode): bool
473473
{
474474
if (isset($sections['INI'])) {
475475
// to get per-test INI settings, we need a dedicated subprocess
@@ -497,35 +497,6 @@ private function shouldRunCleanInSubprocess(array $sections, string $cleanCode):
497497
return false;
498498
}
499499

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

551522
$cleanCode = $this->render($sections['CLEAN']);
552523

553-
if ($this->shouldRunCleanInSubprocess($sections, $cleanCode)) {
524+
if ($this->shouldRunInSubprocess($sections, $cleanCode)) {
554525
$result = JobRunnerRegistry::run(
555526
new Job(
556527
$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: 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)

0 commit comments

Comments
 (0)