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 41 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 |
---|---|---|
|
@@ -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.
not sure I understand this block.
XDEBUG_MODE=coverage
whenpcov
is loaded, for example?In the end the user is still in control: they can provide XDEBUG_MODE=coverage on their own.
- is it true? If user passesXDEBUG_MODE=debug
and Xdebug is loaded (with, let's say,off
mode), then this new code will override it byXDEBUG_MODE=coverage
, no?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.
XDEBUG_MODE=coverage
even if they have PCOV loaded. We can't guarantee other tools will pick this up, but at least we're not standing in the way.XDEBUG_MODE=debug
is no use for us, we have to override it withXDEBUG_MODE=coverage
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.
OK, all should be much more clear in
shallExtendEnvironmentWithXdebugMode
below.