Skip to content

Commit cb8b1ac

Browse files
Merge branch '12.5'
* 12.5: Closes #6446 Do not set xdebug.mode=off for PHPT process when PHPT file has --INI-- section with xdebug.mode Exclude src/autoload.php Revert "Load Xdebug for end-to-end tests" Load Xdebug for end-to-end tests Add test
2 parents a6712d2 + 818e27b commit cb8b1ac

File tree

8 files changed

+157
-5
lines changed

8 files changed

+157
-5
lines changed

src/Runner/CodeCoverage.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,9 @@ public function stop(bool $append, null|false|TargetCollection $covers = null, ?
213213
return;
214214
}
215215

216-
$time = $this->timer()->stop()->asSeconds();
217-
218-
$status = TestStatus::unknown();
216+
$time = $this->timer()->stop()->asSeconds();
217+
$status = TestStatus::unknown();
218+
$this->collecting = false;
219219

220220
if ($this->test !== null) {
221221
if ($this->test->status()->isSuccess()) {
@@ -257,8 +257,7 @@ public function stop(bool $append, null|false|TargetCollection $covers = null, ?
257257

258258
$this->codeCoverage->stop($append, $status, $covers, $uses, $time);
259259

260-
$this->test = null;
261-
$this->collecting = false;
260+
$this->test = null;
262261
}
263262

264263
public function deactivate(): void

src/Util/PHP/DefaultJobRunner.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use function is_resource;
2525
use function proc_close;
2626
use function proc_open;
27+
use function str_starts_with;
2728
use function stream_get_contents;
2829
use function sys_get_temp_dir;
2930
use function tempnam;
@@ -169,6 +170,16 @@ private function buildCommand(Job $job, ?string $file): array
169170
$command = [PHP_BINARY];
170171
$phpSettings = $job->phpSettings();
171172

173+
$xdebugModeConfiguredExplicitly = false;
174+
175+
foreach ($phpSettings as $phpSetting) {
176+
if (str_starts_with($phpSetting, 'xdebug.mode')) {
177+
$xdebugModeConfiguredExplicitly = true;
178+
179+
break;
180+
}
181+
}
182+
172183
if ($runtime->hasPCOV()) {
173184
$pcovSettings = ini_get_all('pcov');
174185

@@ -195,6 +206,7 @@ private function buildCommand(Job $job, ?string $file): array
195206
);
196207

197208
if (
209+
!$xdebugModeConfiguredExplicitly &&
198210
!CodeCoverage::instance()->isActive() &&
199211
xdebug_is_debugger_active() === false &&
200212
!$job->requiresXdebug()
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="../../../../../phpunit.xsd"
4+
bootstrap="src/autoload.php"
5+
beStrictAboutCoverageMetadata="true">
6+
<testsuites>
7+
<testsuite name="default">
8+
<directory>tests</directory>
9+
</testsuite>
10+
</testsuites>
11+
12+
<source>
13+
<include>
14+
<directory>src</directory>
15+
</include>
16+
17+
<exclude>
18+
<file>src/autoload.php</file>
19+
</exclude>
20+
</source>
21+
</phpunit>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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 PHPUnit\TestFixture\Event\RiskyCodeCoverage;
11+
12+
final class Bar
13+
{
14+
public function doSomethingElse(): bool
15+
{
16+
return true;
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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 PHPUnit\TestFixture\Event\RiskyCodeCoverage;
11+
12+
final class Foo
13+
{
14+
public function doSomething(): bool
15+
{
16+
return (new Bar)->doSomethingElse();
17+
}
18+
}
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 PHPUnit\TestFixture\Event\RiskyCodeCoverage;
11+
12+
require __DIR__ . '/Foo.php';
13+
14+
require __DIR__ . '/Bar.php';
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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 PHPUnit\TestFixture\Event\RiskyCodeCoverage;
11+
12+
use PHPUnit\Framework\Attributes\CoversClass;
13+
use PHPUnit\Framework\TestCase;
14+
15+
#[CoversClass(Foo::class)]
16+
final class FooTest extends TestCase
17+
{
18+
public function testSomething(): void
19+
{
20+
$this->assertTrue((new Foo)->doSomething());
21+
}
22+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
--TEST--
2+
The right events are emitted in the right order for a test that is considered risky because it executed code that is not listed as code to be covered or used
3+
--SKIPIF--
4+
<?php declare(strict_types=1);
5+
if (!extension_loaded('xdebug')) {
6+
print 'skip: Extension Xdebug must be loaded.';
7+
}
8+
--INI--
9+
xdebug.mode=coverage
10+
--FILE--
11+
<?php declare(strict_types=1);
12+
$_SERVER['argv'][] = '--do-not-cache-result';
13+
$_SERVER['argv'][] = '--debug';
14+
$_SERVER['argv'][] = '--coverage-text';
15+
$_SERVER['argv'][] = '--configuration';
16+
$_SERVER['argv'][] = __DIR__ . '/_files/test-risky-code-coverage';
17+
18+
require __DIR__ . '/../../bootstrap.php';
19+
20+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
21+
--EXPECTF--
22+
PHPUnit Started (PHPUnit %s using %s)
23+
Test Runner Configured
24+
Bootstrap Finished (%sautoload.php)
25+
Event Facade Sealed
26+
Test Suite Loaded (1 test)
27+
Static Analysis for Code Coverage Started
28+
Static Analysis for Code Coverage Finished (%d cache hits, %d cache misses)
29+
Test Runner Started
30+
Test Suite Sorted
31+
Test Runner Execution Started (1 test)
32+
Test Suite Started (%sphpunit.xml, 1 test)
33+
Test Suite Started (default, 1 test)
34+
Test Suite Started (PHPUnit\TestFixture\Event\RiskyCodeCoverage\FooTest, 1 test)
35+
Test Preparation Started (PHPUnit\TestFixture\Event\RiskyCodeCoverage\FooTest::testSomething)
36+
Test Prepared (PHPUnit\TestFixture\Event\RiskyCodeCoverage\FooTest::testSomething)
37+
Test Passed (PHPUnit\TestFixture\Event\RiskyCodeCoverage\FooTest::testSomething)
38+
Test Considered Risky (PHPUnit\TestFixture\Event\RiskyCodeCoverage\FooTest::testSomething)
39+
This test executed code that is not listed as code to be covered or used:
40+
- PHPUnit\TestFixture\Event\RiskyCodeCoverage\Bar
41+
42+
Test Finished (PHPUnit\TestFixture\Event\RiskyCodeCoverage\FooTest::testSomething)
43+
Test Suite Finished (PHPUnit\TestFixture\Event\RiskyCodeCoverage\FooTest, 1 test)
44+
Test Suite Finished (default, 1 test)
45+
Test Suite Finished (%sphpunit.xml, 1 test)
46+
Test Runner Execution Finished
47+
Test Runner Finished
48+
PHPUnit Finished (Shell Exit Code: 0)

0 commit comments

Comments
 (0)