Skip to content

Commit 078538a

Browse files
Use default values from Thresholds::default()
1 parent 781f34c commit 078538a

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

src/TextUI/Configuration/Merger.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use PHPUnit\TextUI\XmlConfiguration\LoadedFromFileConfiguration;
2424
use PHPUnit\Util\Filesystem;
2525
use SebastianBergmann\CodeCoverage\Report\Html\Colors;
26+
use SebastianBergmann\CodeCoverage\Report\Thresholds;
2627
use SebastianBergmann\Environment\Console;
2728

2829
/**
@@ -169,15 +170,16 @@ public function merge(CliConfiguration $cliConfiguration, XmlConfiguration $xmlC
169170
$pathCoverage = $xmlConfiguration->codeCoverage()->pathCoverage();
170171
}
171172

172-
$defaultColors = Colors::default();
173+
$defaultColors = Colors::default();
174+
$defaultThresholds = Thresholds::default();
173175

174176
$coverageClover = null;
175177
$coverageCobertura = null;
176178
$coverageCrap4j = null;
177179
$coverageCrap4jThreshold = 30;
178180
$coverageHtml = null;
179-
$coverageHtmlLowUpperBound = 50;
180-
$coverageHtmlHighLowerBound = 90;
181+
$coverageHtmlLowUpperBound = $defaultThresholds->lowUpperBound();
182+
$coverageHtmlHighLowerBound = $defaultThresholds->highLowerBound();
181183
$coverageHtmlColorSuccessLow = $defaultColors->successLow();
182184
$coverageHtmlColorSuccessMedium = $defaultColors->successMedium();
183185
$coverageHtmlColorSuccessHigh = $defaultColors->successHigh();
@@ -221,8 +223,8 @@ public function merge(CliConfiguration $cliConfiguration, XmlConfiguration $xmlC
221223
$coverageHtmlLowUpperBound = $xmlConfiguration->codeCoverage()->html()->lowUpperBound();
222224

223225
if ($coverageHtmlLowUpperBound > $coverageHtmlHighLowerBound) {
224-
$coverageHtmlLowUpperBound = 50;
225-
$coverageHtmlHighLowerBound = 90;
226+
$coverageHtmlLowUpperBound = $defaultThresholds->lowUpperBound();
227+
$coverageHtmlHighLowerBound = $defaultThresholds->highLowerBound();
226228
}
227229

228230
$coverageHtmlColorSuccessLow = $xmlConfiguration->codeCoverage()->html()->colorSuccessLow();

src/TextUI/Configuration/Xml/Loader.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
use PHPUnit\Util\Xml\SchemaFinder;
5757
use PHPUnit\Util\Xml\Validator;
5858
use SebastianBergmann\CodeCoverage\Report\Html\Colors;
59+
use SebastianBergmann\CodeCoverage\Report\Thresholds;
5960

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

394395
if ($element) {
395-
$defaultColors = Colors::default();
396+
$defaultColors = Colors::default();
397+
$defaultThresholds = Thresholds::default();
396398

397399
$html = new CodeCoverageHtml(
398400
new Directory(
@@ -401,8 +403,8 @@ private function codeCoverage(string $filename, DOMXPath $xpath): CodeCoverage
401403
(string) $this->getStringAttribute($element, 'outputDirectory')
402404
)
403405
),
404-
$this->getIntegerAttribute($element, 'lowUpperBound', 50),
405-
$this->getIntegerAttribute($element, 'highLowerBound', 90),
406+
$this->getIntegerAttribute($element, 'lowUpperBound', $defaultThresholds->lowUpperBound()),
407+
$this->getIntegerAttribute($element, 'highLowerBound', $defaultThresholds->highLowerBound()),
406408
$this->getStringAttributeWithDefault($element, 'colorSuccessLow', $defaultColors->successLow()),
407409
$this->getStringAttributeWithDefault($element, 'colorSuccessMedium', $defaultColors->successMedium()),
408410
$this->getStringAttributeWithDefault($element, 'colorSuccessHigh', $defaultColors->successHigh()),

tests/unit/TextUI/XmlConfigurationTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use PHPUnit\Runner\TestSuiteSorter;
3333
use PHPUnit\TextUI\XmlConfiguration\CodeCoverage\Filter\Directory;
3434
use SebastianBergmann\CodeCoverage\Report\Html\Colors;
35+
use SebastianBergmann\CodeCoverage\Report\Thresholds;
3536
use stdClass;
3637

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

193-
$defaultColors = Colors::default();
194+
$defaultColors = Colors::default();
195+
$defaultThresholds = Thresholds::default();
194196

195197
$this->assertTrue($codeCoverage->hasHtml());
196198
$this->assertSame(TEST_FILES_PATH . 'coverage', $codeCoverage->html()->target()->path());
197-
$this->assertSame(50, $codeCoverage->html()->lowUpperBound());
198-
$this->assertSame(90, $codeCoverage->html()->highLowerBound());
199+
$this->assertSame($defaultThresholds->lowUpperBound(), $codeCoverage->html()->lowUpperBound());
200+
$this->assertSame($defaultThresholds->highLowerBound(), $codeCoverage->html()->highLowerBound());
199201
$this->assertSame($defaultColors->successLow(), $codeCoverage->html()->colorSuccessLow());
200202
$this->assertSame($defaultColors->successMedium(), $codeCoverage->html()->colorSuccessMedium());
201203
$this->assertSame($defaultColors->successHigh(), $codeCoverage->html()->colorSuccessHigh());

0 commit comments

Comments
 (0)