Skip to content

Commit

Permalink
Add support for no-coverage option (#584)
Browse files Browse the repository at this point in the history
  • Loading branch information
bastien-phi committed Jan 29, 2021
1 parent 96b59db commit 9a94366
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 9 deletions.
23 changes: 14 additions & 9 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,17 @@ parameters:
path: src/Runners/PHPUnit/Options.php

-
message: "#^Parameter \\#21 \\$noTestTokens of class ParaTest\\\\Runners\\\\PHPUnit\\\\Options constructor expects bool, array\\<string\\>\\|bool\\|int\\|string\\|null given\\.$#"
message: "#^Parameter \\#21 \\$noCoverage of class ParaTest\\\\Runners\\\\PHPUnit\\\\Options constructor expects bool, array\\<string\\>\\|bool\\|int\\|string\\|null given\\.$#"
count: 1
path: src/Runners/PHPUnit/Options.php

-
message: "#^Parameter \\#22 \\$parallelSuite of class ParaTest\\\\Runners\\\\PHPUnit\\\\Options constructor expects bool, array\\<string\\>\\|bool\\|int\\|string\\|null given\\.$#"
message: "#^Parameter \\#22 \\$noTestTokens of class ParaTest\\\\Runners\\\\PHPUnit\\\\Options constructor expects bool, array\\<string\\>\\|bool\\|int\\|string\\|null given\\.$#"
count: 1
path: src/Runners/PHPUnit/Options.php

-
message: "#^Parameter \\#23 \\$parallelSuite of class ParaTest\\\\Runners\\\\PHPUnit\\\\Options constructor expects bool, array\\<string\\>\\|bool\\|int\\|string\\|null given\\.$#"
count: 1
path: src/Runners/PHPUnit/Options.php

Expand All @@ -150,37 +155,37 @@ parameters:
path: src/Runners/PHPUnit/Options.php

-
message: "#^Parameter \\#25 \\$path of class ParaTest\\\\Runners\\\\PHPUnit\\\\Options constructor expects string\\|null, array\\<string\\>\\|bool\\|int\\|string\\|null given\\.$#"
message: "#^Parameter \\#26 \\$path of class ParaTest\\\\Runners\\\\PHPUnit\\\\Options constructor expects string\\|null, array\\<string\\>\\|bool\\|int\\|string\\|null given\\.$#"
count: 1
path: src/Runners/PHPUnit/Options.php

-
message: "#^Parameter \\#27 \\$processes of class ParaTest\\\\Runners\\\\PHPUnit\\\\Options constructor expects int, array\\<string\\>\\|bool\\|int\\|string\\|null given\\.$#"
message: "#^Parameter \\#28 \\$processes of class ParaTest\\\\Runners\\\\PHPUnit\\\\Options constructor expects int, array\\<string\\>\\|bool\\|int\\|string\\|null given\\.$#"
count: 1
path: src/Runners/PHPUnit/Options.php

-
message: "#^Parameter \\#28 \\$runner of class ParaTest\\\\Runners\\\\PHPUnit\\\\Options constructor expects string, array\\<string\\>\\|bool\\|int\\|string\\|null given\\.$#"
message: "#^Parameter \\#29 \\$runner of class ParaTest\\\\Runners\\\\PHPUnit\\\\Options constructor expects string, array\\<string\\>\\|bool\\|int\\|string\\|null given\\.$#"
count: 1
path: src/Runners/PHPUnit/Options.php

-
message: "#^Parameter \\#29 \\$stopOnFailure of class ParaTest\\\\Runners\\\\PHPUnit\\\\Options constructor expects bool, array\\<string\\>\\|bool\\|int\\|string\\|null given\\.$#"
message: "#^Parameter \\#30 \\$stopOnFailure of class ParaTest\\\\Runners\\\\PHPUnit\\\\Options constructor expects bool, array\\<string\\>\\|bool\\|int\\|string\\|null given\\.$#"
count: 1
path: src/Runners/PHPUnit/Options.php

-
message: "#^Parameter \\#31 \\$tmpDir of class ParaTest\\\\Runners\\\\PHPUnit\\\\Options constructor expects string, array\\<string\\>\\|bool\\|int\\|string\\|null given\\.$#"
message: "#^Parameter \\#32 \\$tmpDir of class ParaTest\\\\Runners\\\\PHPUnit\\\\Options constructor expects string, array\\<string\\>\\|bool\\|int\\|string\\|null given\\.$#"
count: 1
path: src/Runners/PHPUnit/Options.php

-
message: "#^Parameter \\#33 \\$whitelist of class ParaTest\\\\Runners\\\\PHPUnit\\\\Options constructor expects string\\|null, array\\<string\\>\\|bool\\|int\\|string\\|null given\\.$#"
message: "#^Parameter \\#34 \\$whitelist of class ParaTest\\\\Runners\\\\PHPUnit\\\\Options constructor expects string\\|null, array\\<string\\>\\|bool\\|int\\|string\\|null given\\.$#"
count: 1
path: src/Runners/PHPUnit/Options.php

-
message: "#^Parameter \\#34 \\$orderBy of class ParaTest\\\\Runners\\\\PHPUnit\\\\Options constructor expects string, array\\<string\\>\\|bool\\|int\\|string given\\.$#"
message: "#^Parameter \\#35 \\$orderBy of class ParaTest\\\\Runners\\\\PHPUnit\\\\Options constructor expects string, array\\<string\\>\\|bool\\|int\\|string given\\.$#"
count: 1
path: src/Runners/PHPUnit/Options.php

Expand Down
16 changes: 16 additions & 0 deletions src/Runners/PHPUnit/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ final class Options
private $coverageText;
/** @var string|null */
private $coverageXml;
/** @var bool */
private $noCoverage;
/** @var string */
private $cwd;
/** @var string|null */
Expand Down Expand Up @@ -247,6 +249,7 @@ private function __construct(
?string $logJunit,
?string $logTeamcity,
?int $maxBatchSize,
bool $noCoverage,
bool $noTestTokens,
bool $parallelSuite,
?array $passthru,
Expand Down Expand Up @@ -283,6 +286,7 @@ private function __construct(
$this->logJunit = $logJunit;
$this->logTeamcity = $logTeamcity;
$this->maxBatchSize = $maxBatchSize;
$this->noCoverage = $noCoverage;
$this->noTestTokens = $noTestTokens;
$this->parallelSuite = $parallelSuite;
$this->passthru = $passthru;
Expand Down Expand Up @@ -319,6 +323,7 @@ public static function fromConsoleInput(InputInterface $input, string $cwd): sel
assert(is_bool($options['functional']));
assert($options['log-junit'] === null || is_string($options['log-junit']));
assert($options['log-teamcity'] === null || is_string($options['log-teamcity']));
assert(is_bool($options['no-coverage']));
assert(is_bool($options['no-test-tokens']));
assert($options['order-by'] === null || is_string($options['order-by']));
assert(is_bool($options['parallel-suite']));
Expand Down Expand Up @@ -516,6 +521,7 @@ public static function fromConsoleInput(InputInterface $input, string $cwd): sel
$options['log-junit'],
$options['log-teamcity'],
(int) $options['max-batch-size'],
$options['no-coverage'],
$options['no-test-tokens'],
$options['parallel-suite'],
self::parsePassthru($options['passthru']),
Expand All @@ -536,6 +542,10 @@ public static function fromConsoleInput(InputInterface $input, string $cwd): sel

public function hasCoverage(): bool
{
if ($this->noCoverage) {
return false;
}

return $this->coverageClover !== null
|| $this->coverageCobertura !== null
|| $this->coverageCrap4j !== null
Expand Down Expand Up @@ -672,6 +682,12 @@ public static function setInputDefinition(InputDefinition $inputDefinition): voi
'Max batch size (only for functional mode).',
0
),
new InputOption(
'no-coverage',
null,
InputOption::VALUE_NONE,
'Ignore code coverage configuration.'
),
new InputOption(
'no-test-tokens',
null,
Expand Down
30 changes: 30 additions & 0 deletions test/Unit/Runners/PHPUnit/OptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,36 @@ public function testGatherOptionsFromConfiguration(): void
static::assertTrue($options->hasCoverage());
}

public function testNoCoverageOptionDisablesCoverageOptions(): void
{
$argv = [
'--coverage-clover' => 'COVERAGE-CLOVER',
'--coverage-cobertura' => 'COVERAGE-COBERTURA',
'--coverage-crap4j' => 'COVERAGE-CRAP4J',
'--coverage-html' => 'COVERAGE-HTML',
'--coverage-php' => 'COVERAGE-PHP',
'--coverage-text' => true,
'--coverage-xml' => 'COVERAGE-XML',
'--no-coverage' => true,
];

$options = $this->createOptionsFromArgv($argv, __DIR__);

static::assertFalse($options->hasCoverage());
}

public function testNoCoverageOptionDisablesCoverageConfiguration(): void
{
$argv = [
'--configuration' => $this->fixture('phpunit-fully-configured.xml'),
'--no-coverage' => true,
];

$options = $this->createOptionsFromArgv($argv, __DIR__);

static::assertFalse($options->hasCoverage());
}

public function testFillEnvWithTokens(): void
{
$options = $this->createOptionsFromArgv(['--no-test-tokens' => false]);
Expand Down

0 comments on commit 9a94366

Please sign in to comment.