From 9a94366983ce32c7724fc92e3b544327d4adb9be Mon Sep 17 00:00:00 2001 From: bastien-phi Date: Fri, 29 Jan 2021 16:25:31 +0100 Subject: [PATCH] Add support for no-coverage option (#584) --- phpstan-baseline.neon | 23 ++++++++++------- src/Runners/PHPUnit/Options.php | 16 ++++++++++++ test/Unit/Runners/PHPUnit/OptionsTest.php | 30 +++++++++++++++++++++++ 3 files changed, 60 insertions(+), 9 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index e40c20f2..9a7666df 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -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\\\\|bool\\|int\\|string\\|null given\\.$#" + message: "#^Parameter \\#21 \\$noCoverage of class ParaTest\\\\Runners\\\\PHPUnit\\\\Options constructor expects bool, array\\\\|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\\\\|bool\\|int\\|string\\|null given\\.$#" + message: "#^Parameter \\#22 \\$noTestTokens of class ParaTest\\\\Runners\\\\PHPUnit\\\\Options constructor expects bool, array\\\\|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\\\\|bool\\|int\\|string\\|null given\\.$#" count: 1 path: src/Runners/PHPUnit/Options.php @@ -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\\\\|bool\\|int\\|string\\|null given\\.$#" + message: "#^Parameter \\#26 \\$path of class ParaTest\\\\Runners\\\\PHPUnit\\\\Options constructor expects string\\|null, array\\\\|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\\\\|bool\\|int\\|string\\|null given\\.$#" + message: "#^Parameter \\#28 \\$processes of class ParaTest\\\\Runners\\\\PHPUnit\\\\Options constructor expects int, array\\\\|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\\\\|bool\\|int\\|string\\|null given\\.$#" + message: "#^Parameter \\#29 \\$runner of class ParaTest\\\\Runners\\\\PHPUnit\\\\Options constructor expects string, array\\\\|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\\\\|bool\\|int\\|string\\|null given\\.$#" + message: "#^Parameter \\#30 \\$stopOnFailure of class ParaTest\\\\Runners\\\\PHPUnit\\\\Options constructor expects bool, array\\\\|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\\\\|bool\\|int\\|string\\|null given\\.$#" + message: "#^Parameter \\#32 \\$tmpDir of class ParaTest\\\\Runners\\\\PHPUnit\\\\Options constructor expects string, array\\\\|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\\\\|bool\\|int\\|string\\|null given\\.$#" + message: "#^Parameter \\#34 \\$whitelist of class ParaTest\\\\Runners\\\\PHPUnit\\\\Options constructor expects string\\|null, array\\\\|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\\\\|bool\\|int\\|string given\\.$#" + message: "#^Parameter \\#35 \\$orderBy of class ParaTest\\\\Runners\\\\PHPUnit\\\\Options constructor expects string, array\\\\|bool\\|int\\|string given\\.$#" count: 1 path: src/Runners/PHPUnit/Options.php diff --git a/src/Runners/PHPUnit/Options.php b/src/Runners/PHPUnit/Options.php index 1c1901a1..85315601 100644 --- a/src/Runners/PHPUnit/Options.php +++ b/src/Runners/PHPUnit/Options.php @@ -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 */ @@ -247,6 +249,7 @@ private function __construct( ?string $logJunit, ?string $logTeamcity, ?int $maxBatchSize, + bool $noCoverage, bool $noTestTokens, bool $parallelSuite, ?array $passthru, @@ -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; @@ -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'])); @@ -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']), @@ -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 @@ -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, diff --git a/test/Unit/Runners/PHPUnit/OptionsTest.php b/test/Unit/Runners/PHPUnit/OptionsTest.php index 96efb462..cade6d9c 100644 --- a/test/Unit/Runners/PHPUnit/OptionsTest.php +++ b/test/Unit/Runners/PHPUnit/OptionsTest.php @@ -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]);