Skip to content

Commit 1090876

Browse files
committed
Disable xdebug in subprocess when inactive
1 parent 0cfe722 commit 1090876

File tree

4 files changed

+78
-12
lines changed

4 files changed

+78
-12
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: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use function assert;
1717
use function fclose;
1818
use function file_put_contents;
19+
use function function_exists;
1920
use function fwrite;
2021
use function ini_get_all;
2122
use function is_array;
@@ -27,6 +28,7 @@
2728
use function tempnam;
2829
use function trim;
2930
use function unlink;
31+
use PHPUnit\Runner\CodeCoverage;
3032
use SebastianBergmann\Environment\Runtime;
3133

3234
/**
@@ -174,16 +176,24 @@ private function buildCommand(Job $job, ?string $file): array
174176
),
175177
);
176178
} elseif ($runtime->hasXdebug()) {
177-
$xdebugSettings = ini_get_all('xdebug');
178-
179-
assert($xdebugSettings !== false);
180-
181-
$phpSettings = array_merge(
182-
$phpSettings,
183-
$runtime->getCurrentSettings(
184-
array_keys($xdebugSettings),
185-
),
186-
);
179+
if (
180+
!CodeCoverage::instance()->isActive() &&
181+
function_exists('xdebug_is_debugger_active') &&
182+
xdebug_is_debugger_active() === false
183+
) {
184+
$phpSettings[] = 'xdebug.mode=off';
185+
} else {
186+
$xdebugSettings = ini_get_all('xdebug');
187+
188+
assert($xdebugSettings !== false);
189+
190+
$phpSettings = array_merge(
191+
$phpSettings,
192+
$runtime->getCurrentSettings(
193+
array_keys($xdebugSettings),
194+
),
195+
);
196+
}
187197
}
188198

189199
$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: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
}
8+
--FILE--
9+
<?php declare(strict_types=1);
10+
$_SERVER['argv'][] = '--do-not-cache-result';
11+
$_SERVER['argv'][] = '--no-configuration';
12+
$_SERVER['argv'][] = '--process-isolation';
13+
$_SERVER['argv'][] = '--debug';
14+
$_SERVER['argv'][] = __DIR__ . '/_files/XdebugIsDisabled.php';
15+
16+
require __DIR__ . '/../../bootstrap.php';
17+
18+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
19+
--EXPECTF--
20+
PHPUnit Started (PHPUnit %s using %s)
21+
Test Runner Configured
22+
Event Facade Sealed
23+
Test Suite Loaded (1 test)
24+
Test Runner Started
25+
Test Suite Sorted
26+
Test Runner Execution Started (1 test)
27+
Test Suite Started (PHPUnit\TestFixture\Event\XdebugIsDisabled, 1 test)
28+
Test Preparation Started (PHPUnit\TestFixture\Event\XdebugIsDisabled::testOne)
29+
Test Prepared (PHPUnit\TestFixture\Event\XdebugIsDisabled::testOne)
30+
Test Passed (PHPUnit\TestFixture\Event\XdebugIsDisabled::testOne)
31+
Test Finished (PHPUnit\TestFixture\Event\XdebugIsDisabled::testOne)
32+
Test Suite Finished (PHPUnit\TestFixture\Event\XdebugIsDisabled, 1 test)
33+
Test Runner Execution Finished
34+
Test Runner Finished
35+
PHPUnit Finished (Shell Exit Code: 0)

0 commit comments

Comments
 (0)