-
-
Notifications
You must be signed in to change notification settings - Fork 154
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
Request coverage reports with command line args #1375
Changes from 3 commits
5765c6d
2fad88a
3e0a645
838441c
1f30aab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,8 +38,13 @@ | |
use Infection\AbstractTestFramework\MemoryUsageAware; | ||
use Infection\PhpParser\Visitor\IgnoreNode\PhpUnitCodeCoverageAnnotationIgnorer; | ||
use Infection\TestFramework\AbstractTestFrameworkAdapter; | ||
use Infection\TestFramework\CommandLineArgumentsAndOptionsBuilder; | ||
use Infection\TestFramework\CommandLineBuilder; | ||
use Infection\TestFramework\Config\InitialConfigBuilder; | ||
use Infection\TestFramework\Config\MutationConfigBuilder; | ||
use Infection\TestFramework\IgnoresAdditionalNodes; | ||
use Infection\TestFramework\ProvidesInitialRunOnlyOptions; | ||
use Infection\TestFramework\VersionParser; | ||
use function Safe\preg_match; | ||
use function Safe\sprintf; | ||
use function version_compare; | ||
|
@@ -52,11 +57,56 @@ class PhpUnitAdapter extends AbstractTestFrameworkAdapter implements IgnoresAddi | |
{ | ||
public const COVERAGE_DIR = 'coverage-xml'; | ||
|
||
private $tmpDir; | ||
|
||
private $jUnitFilePath; | ||
|
||
public function __construct( | ||
string $testFrameworkExecutable, | ||
string $tmpDir, | ||
string $jUnitFilePath, | ||
InitialConfigBuilder $initialConfigBuilder, | ||
MutationConfigBuilder $mutationConfigBuilder, | ||
CommandLineArgumentsAndOptionsBuilder $argumentsAndOptionsBuilder, | ||
VersionParser $versionParser, | ||
CommandLineBuilder $commandLineBuilder, | ||
?string $version = null | ||
) { | ||
parent::__construct($testFrameworkExecutable, $initialConfigBuilder, $mutationConfigBuilder, $argumentsAndOptionsBuilder, $versionParser, $commandLineBuilder, $version); | ||
|
||
$this->tmpDir = $tmpDir; | ||
$this->jUnitFilePath = $jUnitFilePath; | ||
} | ||
|
||
public function hasJUnitReport(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Returns array of arguments to pass them into the Initial Run Process | ||
* | ||
* @param string[] $phpExtraArgs | ||
* | ||
* @return string[] | ||
*/ | ||
public function getInitialTestRunCommandLine( | ||
string $extraOptions, | ||
array $phpExtraArgs, | ||
bool $skipCoverage | ||
): array { | ||
if ($skipCoverage === 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. question: is it any better than 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. For one, Is there a fixer for 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. I was very hesitant about It is not like someone would extend the very this class, but if this happens, identical comparison gets us prepared. For example, if you were using 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. makes sense I know the reason why it looks weird for me, because I've been using phpstan with strict rules for 2 years on my job, and it's impossible to use non-boolean comparison there. Look at this code with strict rules: $null = rand(0, 1) === 0 ? null : true;
if (!$null) {
} error: Regarding your example, I guess it's impossible to do it: https://phpstan.org/r/b07764ac-22c8-4c06-ad83-a19ba9e09381 - we can pass only booleans to the parent (original) method. Anyway, it's not critical, we can leave it. Just not usual usage for me, that's why I asked. 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. Sure. It's nice to have PHPStan warn you about improper negation, but it's a liability nevertheless. E.g. where negation can be improper, |
||
$extraOptions = trim(sprintf( | ||
'%s --coverage-xml=%s --log-junit=%s', | ||
$extraOptions, | ||
$this->tmpDir . '/' . self::COVERAGE_DIR, | ||
$this->jUnitFilePath // escapeshellarg() is done up the stack in ArgumentsAndOptionsBuilder | ||
)); | ||
} | ||
|
||
return parent::getInitialTestRunCommandLine($extraOptions, $phpExtraArgs, $skipCoverage); | ||
} | ||
|
||
public function testsPass(string $output): bool | ||
{ | ||
if (preg_match('/failures!/i', $output)) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,7 +52,7 @@ public function build(string $configPath, string $extraOptions): array | |
'--configuration', | ||
$configPath, | ||
], | ||
explode(' ', $extraOptions) | ||
explode(' ', $extraOptions) // FIXME might break space-containing paths | ||
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 fixing this issue in this PR, long enough already. |
||
); | ||
|
||
return array_filter($options); | ||
|
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.
Extending constructors does not break the LSP.