Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Framework/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ final public function run(): void
$this,
$this->runClassInSeparateProcess && !$this->runTestInSeparateProcess,
$this->preserveGlobalState,
$this->requiresXdebug(),
);
}

Expand Down Expand Up @@ -2589,6 +2590,11 @@ private function requirementsNotSatisfied(): bool
return (new Requirements)->requirementsNotSatisfiedFor(static::class, $this->methodName) !== [];
}

private function requiresXdebug(): bool
{
return (new Requirements)->requiresXdebug(static::class, $this->methodName);
}

/**
* @see https://github.com/sebastianbergmann/phpunit/issues/6095
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Framework/TestRunner/IsolatedTestRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
*/
interface IsolatedTestRunner
{
public function run(TestCase $test, bool $runEntireClass, bool $preserveGlobalState): void;
public function run(TestCase $test, bool $runEntireClass, bool $preserveGlobalState, bool $requiresXdebug): void;
}
4 changes: 2 additions & 2 deletions src/Framework/TestRunner/IsolatedTestRunnerRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ final class IsolatedTestRunnerRegistry
{
private static ?IsolatedTestRunner $runner = null;

public static function run(TestCase $test, bool $runEntireClass, bool $preserveGlobalState): void
public static function run(TestCase $test, bool $runEntireClass, bool $preserveGlobalState, bool $requiresXdebug): void
{
if (self::$runner === null) {
self::$runner = new SeparateProcessTestRunner;
}

self::$runner->run($test, $runEntireClass, $preserveGlobalState);
self::$runner->run($test, $runEntireClass, $preserveGlobalState, $requiresXdebug);
}

public static function set(IsolatedTestRunner $runner): void
Expand Down
4 changes: 2 additions & 2 deletions src/Framework/TestRunner/SeparateProcessTestRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ final class SeparateProcessTestRunner implements IsolatedTestRunner
* @throws NoPreviousThrowableException
* @throws ProcessIsolationException
*/
public function run(TestCase $test, bool $runEntireClass, bool $preserveGlobalState): void
public function run(TestCase $test, bool $runEntireClass, bool $preserveGlobalState, bool $requiresXdebug): void
{
$class = new ReflectionClass($test);

Expand Down Expand Up @@ -139,7 +139,7 @@ public function run(TestCase $test, bool $runEntireClass, bool $preserveGlobalSt

assert($code !== '');

JobRunnerRegistry::runTestJob(new Job($code), $processResultFile, $test);
JobRunnerRegistry::runTestJob(new Job($code, requiresXdebug: $requiresXdebug), $processResultFile, $test);

@unlink($serializedConfiguration);
}
Expand Down
13 changes: 13 additions & 0 deletions src/Metadata/Api/Requirements.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,17 @@ public function requirementsNotSatisfiedFor(string $className, string $methodNam

return $notSatisfied;
}

public function requiresXdebug(string $className, string $methodName): bool
{
foreach (Registry::parser()->forClassAndMethod($className, $methodName) as $metadata) {
if ($metadata->isRequiresPhpExtension()) {
if ($metadata->extension() === 'xdebug') {
return true;
}
}
}

return false;
}
}
9 changes: 7 additions & 2 deletions src/Util/PHP/DefaultJobRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public function run(Job $job): Result
$job->arguments(),
null,
$job->redirectErrors(),
$job->requiresXdebug(),
);
}

Expand Down Expand Up @@ -192,8 +193,12 @@ private function buildCommand(Job $job, ?string $file): array
),
);

if (!CodeCoverage::instance()->isActive() &&
xdebug_is_debugger_active() === false) {
if (
!CodeCoverage::instance()->isActive() &&
xdebug_is_debugger_active() === false &&
!$job->requiresXdebug()
) {
// disable xdebug to speedup test execution
$phpSettings['xdebug.mode'] = 'xdebug.mode=off';
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/Util/PHP/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
*/
private ?string $input;
private bool $redirectErrors;
private bool $requiresXdebug;

/**
* @param non-empty-string $code
Expand All @@ -51,14 +52,15 @@
* @param list<non-empty-string> $arguments
* @param ?non-empty-string $input
*/
public function __construct(string $code, array $phpSettings = [], array $environmentVariables = [], array $arguments = [], ?string $input = null, bool $redirectErrors = false)
public function __construct(string $code, array $phpSettings = [], array $environmentVariables = [], array $arguments = [], ?string $input = null, bool $redirectErrors = false, bool $requiresXdebug = false)
{
$this->code = $code;
$this->phpSettings = $phpSettings;
$this->environmentVariables = $environmentVariables;
$this->arguments = $arguments;
$this->input = $input;
$this->redirectErrors = $redirectErrors;
$this->requiresXdebug = $requiresXdebug;
}

/**
Expand Down Expand Up @@ -135,4 +137,9 @@ public function redirectErrors(): bool
{
return $this->redirectErrors;
}

public function requiresXdebug(): bool
{
return $this->requiresXdebug;
}
}
24 changes: 24 additions & 0 deletions tests/end-to-end/regression/6105.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
https://github.com/sebastianbergmann/phpunit/issues/6105
--SKIPIF--
<?php if(!extension_loaded('xdebug')) {
print 'skip: xdebug is not loaded';
}
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = __DIR__ . '/6105/IssueTest6105.php';

require_once __DIR__ . '/../../bootstrap.php';
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

Runtime: %s
Configuration: %s

.. 2 / 2 (100%)

Time: %s, Memory: %s

OK (2 tests, 3 assertions)
40 changes: 40 additions & 0 deletions tests/end-to-end/regression/6105/IssueTest6105.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace IssueTest6105;

use function header;
use function ob_get_clean;
use function ob_start;
use PHPUnit\Framework\Attributes\CoversNothing;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use PHPUnit\Framework\TestCase;

#[CoversNothing]
class IssueTest6105 extends TestCase
{
public function test_1(): void
{
$this->assertTrue(true);
}

#[RunInSeparateProcess]
#[RequiresPhpExtension('xdebug')]
public function test_case_2_check(): void
{
ob_start();
header('X-Test: Testing');
print 'asd';
$content = ob_get_clean();

$this->assertSame('asd', $content);
$this->assertSame(['X-Test: Testing'], xdebug_get_headers());
}
}
Loading