Skip to content
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

Add quiet-coverage option #1345

Open
wants to merge 1 commit into
base: 3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/Plugins/Coverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ final class Coverage implements AddsOutput, HandlesArguments
*/
private const EXACTLY_OPTION = 'exactly';

/**
* @var string
*/
private const QUIET_COVERAGE_OPTION = 'quiet-coverage';

/**
* Whether it should show the coverage or not.
*/
Expand All @@ -52,6 +57,11 @@ final class Coverage implements AddsOutput, HandlesArguments
*/
public ?float $coverageExactly = null;

/**
* Whether it should hide files where coverage is 100% or not
*/
public bool $quietCoverage = false;

/**
* Creates a new Plugin instance.
*/
Expand All @@ -66,7 +76,12 @@ public function __construct(private readonly OutputInterface $output)
public function handleArguments(array $originals): array
{
$arguments = [...[''], ...array_values(array_filter($originals, function (string $original): bool {
foreach ([self::COVERAGE_OPTION, self::MIN_OPTION, self::EXACTLY_OPTION] as $option) {
foreach ([
self::COVERAGE_OPTION,
self::MIN_OPTION,
self::EXACTLY_OPTION,
self::QUIET_COVERAGE_OPTION
] as $option) {
if ($original === sprintf('--%s', $option)) {
return true;
}
Expand All @@ -89,6 +104,7 @@ public function handleArguments(array $originals): array
$inputs[] = new InputOption(self::COVERAGE_OPTION, null, InputOption::VALUE_NONE);
$inputs[] = new InputOption(self::MIN_OPTION, null, InputOption::VALUE_REQUIRED);
$inputs[] = new InputOption(self::EXACTLY_OPTION, null, InputOption::VALUE_REQUIRED);
$inputs[] = new InputOption(self::QUIET_COVERAGE_OPTION, null, InputOption::VALUE_NONE);

$input = new ArgvInput($arguments, new InputDefinition($inputs));
if ((bool) $input->getOption(self::COVERAGE_OPTION)) {
Expand Down Expand Up @@ -129,6 +145,10 @@ public function handleArguments(array $originals): array
$this->coverageExactly = (float) $exactlyOption;
}

if ((bool) $input->getOption(self::COVERAGE_OPTION)) {
$this->quietCoverage = true;
}

if ($_SERVER['COLLISION_PRINTER_COMPACT'] ?? false) {
$this->compact = true;
}
Expand All @@ -153,7 +173,7 @@ public function addOutput(int $exitCode): int
exit(1);
}

$coverage = \Pest\Support\Coverage::report($this->output, $this->compact);
$coverage = \Pest\Support\Coverage::report($this->output, $this->compact, $this->quietCoverage);
$exitCode = (int) ($coverage < $this->coverageMin);

if ($exitCode === 0 && $this->coverageExactly !== null) {
Expand Down
5 changes: 4 additions & 1 deletion src/Plugins/Help.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ private function getContent(): array
], [
'arg' => '--coverage --min',
'desc' => 'Set the minimum required coverage percentage, and fail if not met',
], ...$content['Code Coverage']];
], ...$content['Code Coverage'], [
'arg' => '--quiet-coverage ',
'desc' => 'Do not report any files where code coverage is 100%',
]];

$content['Mutation Testing'] = [[
'arg' => '--mutate ',
Expand Down
9 changes: 6 additions & 3 deletions src/Support/Coverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,11 @@ public static function usingXdebug(): bool
* Reports the code coverage report to the
* console and returns the result in float.
*/
public static function report(OutputInterface $output, bool $compact = false): float
{
public static function report(
OutputInterface $output,
bool $compact = false,
bool $quietCoverage = false,
): float {
if (! file_exists($reportPath = self::getPath())) {
if (self::usingXdebug()) {
$output->writeln(
Expand Down Expand Up @@ -113,7 +116,7 @@ public static function report(OutputInterface $output, bool $compact = false): f
? '100.0'
: number_format($file->percentageOfExecutedLines()->asFloat(), 1, '.', '');

if ($percentage === '100.0' && $compact) {
if ($percentage === '100.0' && ($compact || $quietCoverage)) {
continue;
}

Expand Down