Skip to content

Commit 4e52bb6

Browse files
staabmsebastianbergmann
authored andcommitted
Disable xdebug in subprocess when inactive
1 parent fb8ce4d commit 4e52bb6

File tree

4 files changed

+70
-2
lines changed

4 files changed

+70
-2
lines changed

src/Runner/PHPT/PhptTestCase.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -906,8 +906,6 @@ private function settings(bool $collectCoverage): array
906906
if (extension_loaded('xdebug')) {
907907
if ($collectCoverage) {
908908
$settings[] = 'xdebug.mode=coverage';
909-
} else {
910-
$settings[] = 'xdebug.mode=off';
911909
}
912910
}
913911

src/Util/PHP/DefaultJobRunner.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use function tempnam;
2828
use function trim;
2929
use function unlink;
30+
use PHPUnit\Runner\CodeCoverage;
3031
use SebastianBergmann\Environment\Runtime;
3132

3233
/**
@@ -184,6 +185,14 @@ private function buildCommand(Job $job, ?string $file): array
184185
array_keys($xdebugSettings),
185186
),
186187
);
188+
189+
// disable xdebug if not required to reduce xdebug performance overhead in subprocesses
190+
if (
191+
!CodeCoverage::instance()->isActive() &&
192+
xdebug_is_debugger_active() === false
193+
) {
194+
$phpSettings['xdebug.mode'] = 'xdebug.mode=off';
195+
}
187196
}
188197

189198
$command = array_merge($command, $this->settingsToParameters($phpSettings));
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <sebastian@phpunit.de>
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 PHPUnit\TestFixture\Event;
11+
12+
use function extension_loaded;
13+
use function ini_get;
14+
use PHPUnit\Framework\TestCase;
15+
16+
final class XdebugIsDisabled extends TestCase
17+
{
18+
public function testOne(): void
19+
{
20+
$this->assertTrue(extension_loaded('xdebug'));
21+
$this->assertSame('', (string) ini_get('xdebug.mode'));
22+
}
23+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--TEST--
2+
Subprocesses auto-disable xdebug when no debugger is attached.
3+
--SKIPIF--
4+
<?php declare(strict_types=1);
5+
if (!extension_loaded('xdebug')) {
6+
print 'skip: Extension xdebug must be loaded.';
7+
} elseif (xdebug_is_debugger_active() === true) {
8+
print 'skip: Debugger must not be attached.';
9+
}
10+
11+
--FILE--
12+
<?php declare(strict_types=1);
13+
$_SERVER['argv'][] = '--do-not-cache-result';
14+
$_SERVER['argv'][] = '--no-configuration';
15+
$_SERVER['argv'][] = '--process-isolation';
16+
$_SERVER['argv'][] = '--debug';
17+
$_SERVER['argv'][] = __DIR__ . '/_files/XdebugIsDisabled.php';
18+
19+
require __DIR__ . '/../../bootstrap.php';
20+
21+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
22+
--EXPECTF--
23+
PHPUnit Started (PHPUnit %s using %s)
24+
Test Runner Configured
25+
Event Facade Sealed
26+
Test Suite Loaded (1 test)
27+
Test Runner Started
28+
Test Suite Sorted
29+
Test Runner Execution Started (1 test)
30+
Test Suite Started (PHPUnit\TestFixture\Event\XdebugIsDisabled, 1 test)
31+
Test Preparation Started (PHPUnit\TestFixture\Event\XdebugIsDisabled::testOne)
32+
Test Prepared (PHPUnit\TestFixture\Event\XdebugIsDisabled::testOne)
33+
Test Passed (PHPUnit\TestFixture\Event\XdebugIsDisabled::testOne)
34+
Test Finished (PHPUnit\TestFixture\Event\XdebugIsDisabled::testOne)
35+
Test Suite Finished (PHPUnit\TestFixture\Event\XdebugIsDisabled, 1 test)
36+
Test Runner Execution Finished
37+
Test Runner Finished
38+
PHPUnit Finished (Shell Exit Code: 0)

0 commit comments

Comments
 (0)