Skip to content

Commit

Permalink
Use default values from Thresholds::default()
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Mar 8, 2022
1 parent 781f34c commit 6aa2fbc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
12 changes: 7 additions & 5 deletions src/TextUI/Configuration/Merger.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use PHPUnit\TextUI\XmlConfiguration\LoadedFromFileConfiguration;
use PHPUnit\Util\Filesystem;
use SebastianBergmann\CodeCoverage\Report\Html\Colors;
use SebastianBergmann\CodeCoverage\Report\Thresholds;
use SebastianBergmann\Environment\Console;

/**
Expand Down Expand Up @@ -169,15 +170,16 @@ public function merge(CliConfiguration $cliConfiguration, XmlConfiguration $xmlC
$pathCoverage = $xmlConfiguration->codeCoverage()->pathCoverage();
}

$defaultColors = Colors::default();
$defaultColors = Colors::default();
$defaultThresholds = Thresholds::default();

$coverageClover = null;
$coverageCobertura = null;
$coverageCrap4j = null;
$coverageCrap4jThreshold = 30;
$coverageHtml = null;
$coverageHtmlLowUpperBound = 50;
$coverageHtmlHighLowerBound = 90;
$coverageHtmlLowUpperBound = $defaultThresholds->highLowerBound();
$coverageHtmlHighLowerBound = $defaultThresholds->lowUpperBound();
$coverageHtmlColorSuccessLow = $defaultColors->successLow();
$coverageHtmlColorSuccessMedium = $defaultColors->successMedium();
$coverageHtmlColorSuccessHigh = $defaultColors->successHigh();
Expand Down Expand Up @@ -221,8 +223,8 @@ public function merge(CliConfiguration $cliConfiguration, XmlConfiguration $xmlC
$coverageHtmlLowUpperBound = $xmlConfiguration->codeCoverage()->html()->lowUpperBound();

if ($coverageHtmlLowUpperBound > $coverageHtmlHighLowerBound) {
$coverageHtmlLowUpperBound = 50;
$coverageHtmlHighLowerBound = 90;
$coverageHtmlLowUpperBound = $defaultThresholds->highLowerBound();
$coverageHtmlHighLowerBound = $defaultThresholds->lowUpperBound();
}

$coverageHtmlColorSuccessLow = $xmlConfiguration->codeCoverage()->html()->colorSuccessLow();
Expand Down
8 changes: 5 additions & 3 deletions src/TextUI/Configuration/Xml/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
use PHPUnit\Util\Xml\SchemaFinder;
use PHPUnit\Util\Xml\Validator;
use SebastianBergmann\CodeCoverage\Report\Html\Colors;
use SebastianBergmann\CodeCoverage\Report\Thresholds;

/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
Expand Down Expand Up @@ -392,7 +393,8 @@ private function codeCoverage(string $filename, DOMXPath $xpath): CodeCoverage
$element = $this->element($xpath, 'coverage/report/html');

if ($element) {
$defaultColors = Colors::default();
$defaultColors = Colors::default();
$defaultThresholds = Thresholds::default();

$html = new CodeCoverageHtml(
new Directory(
Expand All @@ -401,8 +403,8 @@ private function codeCoverage(string $filename, DOMXPath $xpath): CodeCoverage
(string) $this->getStringAttribute($element, 'outputDirectory')
)
),
$this->getIntegerAttribute($element, 'lowUpperBound', 50),
$this->getIntegerAttribute($element, 'highLowerBound', 90),
$this->getIntegerAttribute($element, 'lowUpperBound', $defaultThresholds->lowUpperBound()),
$this->getIntegerAttribute($element, 'highLowerBound', $defaultThresholds->highLowerBound()),
$this->getStringAttributeWithDefault($element, 'colorSuccessLow', $defaultColors->successLow()),
$this->getStringAttributeWithDefault($element, 'colorSuccessMedium', $defaultColors->successMedium()),
$this->getStringAttributeWithDefault($element, 'colorSuccessHigh', $defaultColors->successHigh()),
Expand Down
8 changes: 5 additions & 3 deletions tests/unit/TextUI/XmlConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use PHPUnit\Runner\TestSuiteSorter;
use PHPUnit\TextUI\XmlConfiguration\CodeCoverage\Filter\Directory;
use SebastianBergmann\CodeCoverage\Report\Html\Colors;
use SebastianBergmann\CodeCoverage\Report\Thresholds;
use stdClass;

#[Medium]
Expand Down Expand Up @@ -190,12 +191,13 @@ public function testCodeCoverageConfigurationIsReadCorrectly(): void
$this->assertTrue($codeCoverage->hasCrap4j());
$this->assertSame(TEST_FILES_PATH . 'crap4j.xml', $codeCoverage->crap4j()->target()->path());

$defaultColors = Colors::default();
$defaultColors = Colors::default();
$defaultThresholds = Thresholds::default();

$this->assertTrue($codeCoverage->hasHtml());
$this->assertSame(TEST_FILES_PATH . 'coverage', $codeCoverage->html()->target()->path());
$this->assertSame(50, $codeCoverage->html()->lowUpperBound());
$this->assertSame(90, $codeCoverage->html()->highLowerBound());
$this->assertSame($defaultThresholds->lowUpperBound(), $codeCoverage->html()->lowUpperBound());
$this->assertSame($defaultThresholds->highLowerBound(), $codeCoverage->html()->highLowerBound());
$this->assertSame($defaultColors->successLow(), $codeCoverage->html()->colorSuccessLow());
$this->assertSame($defaultColors->successMedium(), $codeCoverage->html()->colorSuccessMedium());
$this->assertSame($defaultColors->successHigh(), $codeCoverage->html()->colorSuccessHigh());
Expand Down

0 comments on commit 6aa2fbc

Please sign in to comment.