New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set XDEBUG_MODE for processes with coverage #1518
Changes from 36 commits
5390f63
317e5ce
f71de68
fd77c35
90017c6
6dd84fe
a8a3db7
a645bee
99162ef
6f72869
4999b9a
97ba8e1
5fd95df
41433ee
aa1e089
fd56f5d
8af83b2
7b12fc4
8070082
ceee8e2
9f6d313
ae72703
c3aa985
9925caf
cccb00f
51f3d8f
ba71b3b
b59fe4f
2d9435e
2b6b4d0
a7c2f2f
394e1dc
4597545
eec4a33
e958091
db7bd12
2b7aa7b
e363c79
50ee06f
17f84ee
4270a9b
2b8a324
20a9b99
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
xdebug.mode=off |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,12 @@ | |
|
||
namespace Infection\Process; | ||
|
||
use function array_merge; | ||
use Composer\XdebugHandler\PhpConfig; | ||
use Composer\XdebugHandler\XdebugHandler; | ||
use function extension_loaded; | ||
use function ini_get as ini_get_unsafe; | ||
use const PHP_SAPI; | ||
use Symfony\Component\Process\Process; | ||
|
||
/** | ||
|
@@ -57,6 +62,27 @@ public function start(?callable $callback = null, ?array $env = null): void | |
$phpConfig = new PhpConfig(); | ||
$phpConfig->useOriginal(); | ||
|
||
// We don't want to add XDEBUG_MODE=coverage if: | ||
// - PCOV is loaded | ||
// - PHPDBG is in use | ||
// - Xdebug wasn't ever there | ||
// - or Xdebug isn't version 3+ | ||
if ( | ||
!extension_loaded('pcov') || | ||
PHP_SAPI !== 'phpdbg' || | ||
XdebugHandler::getSkippedVersion() !== '' || | ||
// Any other value but false means Xdebug 3 is loaded. Xdebug 2 didn't have | ||
// it too, but it has coverage enabled at all times. | ||
ini_get_unsafe('xdebug.mode') !== false | ||
) { | ||
// Why going through all the trouble above? We don't want to enable | ||
// Xdebug when there are more compelling choices. In the end the user is | ||
// still in control: they can provide XDEBUG_MODE=coverage on their own. | ||
$env = array_merge($env ?? [], [ | ||
'XDEBUG_MODE' => 'coverage', | ||
]); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure I understand this block.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, all should be much more clear in |
||
|
||
parent::start($callback, $env ?? []); | ||
|
||
$phpConfig->usePersistent(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ | |
use Infection\FileSystem\Locator\FileNotFound; | ||
use Infection\TestFramework\Coverage\JUnit\JUnitReportLocator; | ||
use Infection\TestFramework\Coverage\XmlReport\IndexXmlCoverageLocator; | ||
use function ini_get as ini_get_unsafe; | ||
use const PHP_EOL; | ||
use const PHP_SAPI; | ||
use function Safe\preg_match; | ||
|
@@ -175,6 +176,7 @@ private function hasCoverageGeneratorEnabled(): bool | |
|| XdebugHandler::isXdebugActive() | ||
|| extension_loaded('pcov') | ||
|| XdebugHandler::getSkippedVersion() !== '' | ||
|| ini_get_unsafe('xdebug.mode') !== false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This means we're using Xdebug 3 (as |
||
|| $this->isXdebugIncludedInInitialTestPhpOptions() | ||
|| $this->isPcovIncludedInInitialTestPhpOptions(); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
/** | ||
* This code is licensed under the BSD 3-Clause License. | ||
* | ||
* Copyright (c) 2017, Maks Rafalko | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright notice, this | ||
* list of conditions and the following disclaimer. | ||
* | ||
* * Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* * Neither the name of the copyright holder nor the names of its | ||
* contributors may be used to endorse or promote products derived from | ||
* this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Infection\Tests\Process; | ||
|
||
use Composer\XdebugHandler\XdebugHandler; | ||
use function extension_loaded; | ||
use Infection\Process\OriginalPhpProcess; | ||
use function ini_get as ini_get_unsafe; | ||
use const PHP_SAPI; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Process\Process; | ||
|
||
final class OriginalPhpProcessTest extends TestCase | ||
{ | ||
public function test_it_extends_symfony_process(): void | ||
{ | ||
$process = new OriginalPhpProcess([]); | ||
|
||
$this->assertInstanceOf(Process::class, $process); | ||
} | ||
|
||
public function test_it_takes_command_line(): void | ||
{ | ||
$process = new OriginalPhpProcess(['foo']); | ||
$this->assertStringContainsString('foo', $process->getCommandLine()); | ||
} | ||
|
||
/** | ||
* @group integration | ||
*/ | ||
public function test_it_injects_xdebug_env_vars(): void | ||
{ | ||
$process = new OriginalPhpProcess(['env']); | ||
$process->run(null, ['TESTING' => 'test']); | ||
|
||
if ( | ||
extension_loaded('pcov') || | ||
PHP_SAPI === 'phpdbg' || | ||
XdebugHandler::getSkippedVersion() !== '' || | ||
ini_get_unsafe('xdebug.mode') !== false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as in #1518 (comment), seems like here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, we need to properly DI test this, without this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Three weeks later DI stuff isn't here, but it looks like I was able to figure it out: here we assume that |
||
) { | ||
$this->assertStringContainsString('XDEBUG_MODE=coverage', $process->getOutput()); | ||
} else { | ||
$this->assertStringNotContainsString('XDEBUG_MODE=coverage', $process->getOutput()); | ||
} | ||
|
||
$this->assertStringContainsString('TESTING=test', $process->getOutput()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be
&&
but not||
between all the conditions.Otherwise, if the current case is
phpdbg
, the this first condition will result totrue
andXDEBUG_MODE=coverage
will be added