Skip to content

Commit 36bbd10

Browse files
committed
Adds theme support to code coverage.
- See sebastianbergmann/php-code-coverage#1036
1 parent e41231b commit 36bbd10

File tree

9 files changed

+49
-15
lines changed

9 files changed

+49
-15
lines changed

composer.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
"security": "https://github.com/sebastianbergmann/phpunit/security/policy"
2222
},
2323
"prefer-stable": true,
24+
"repositories": [
25+
{
26+
"type": "vcs",
27+
"url": "https://github.com/gammamatrix/php-code-coverage.git"
28+
}
29+
],
2430
"require": {
2531
"php": ">=8.2",
2632
"ext-dom": "*",
@@ -32,7 +38,7 @@
3238
"myclabs/deep-copy": "^1.10.1",
3339
"phar-io/manifest": "^2.0.3",
3440
"phar-io/version": "^3.0.2",
35-
"phpunit/php-code-coverage": "^11.0",
41+
"phpunit/php-code-coverage": "dev-update-to-bootstrap-5",
3642
"phpunit/php-file-iterator": "^5.0",
3743
"phpunit/php-invoker": "^5.0",
3844
"phpunit/php-text-template": "^4.0",

composer.lock

+19-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpunit.xsd

+1
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@
316316
<xs:attribute name="colorWarning" type="xs:string" default="#fcf8e3"/>
317317
<xs:attribute name="colorDanger" type="xs:string" default="#f2dede"/>
318318
<xs:attribute name="customCssFile" type="xs:string"/>
319+
<xs:attribute name="theme" type="xs:string"/>
319320
</xs:complexType>
320321
<xs:complexType name="coverageReportTextType">
321322
<xs:attribute name="outputFile" type="xs:anyURI" use="required"/>

src/Runner/CodeCoverage.php

+1
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ public function generateReports(Printer $printer, Configuration $configuration):
282282
$configuration->coverageHtmlColorSuccessHigh(),
283283
$configuration->coverageHtmlColorWarning(),
284284
$configuration->coverageHtmlColorDanger(),
285+
$configuration->coverageHtmlTheme(),
285286
),
286287
Thresholds::from(
287288
$configuration->coverageHtmlLowUpperBound(),

src/TextUI/Configuration/Configuration.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
private string $coverageHtmlColorWarning;
4646
private string $coverageHtmlColorDanger;
4747
private ?string $coverageHtmlCustomCssFile;
48+
private string $coverageHtmlTheme;
4849
private ?string $coveragePhp;
4950
private ?string $coverageText;
5051
private bool $coverageTextShowUncoveredFiles;
@@ -146,7 +147,7 @@
146147
* @psalm-param non-empty-list<non-empty-string> $testSuffixes
147148
* @psalm-param list<array{className: class-string, parameters: array<string, string>}> $extensionBootstrappers
148149
*/
149-
public function __construct(array $cliArguments, ?string $configurationFile, ?string $bootstrap, bool $cacheResult, ?string $cacheDirectory, ?string $coverageCacheDirectory, Source $source, string $testResultCacheFile, ?string $coverageClover, ?string $coverageCobertura, ?string $coverageCrap4j, int $coverageCrap4jThreshold, ?string $coverageHtml, int $coverageHtmlLowUpperBound, int $coverageHtmlHighLowerBound, string $coverageHtmlColorSuccessLow, string $coverageHtmlColorSuccessMedium, string $coverageHtmlColorSuccessHigh, string $coverageHtmlColorWarning, string $coverageHtmlColorDanger, ?string $coverageHtmlCustomCssFile, ?string $coveragePhp, ?string $coverageText, bool $coverageTextShowUncoveredFiles, bool $coverageTextShowOnlySummary, ?string $coverageXml, bool $pathCoverage, bool $ignoreDeprecatedCodeUnitsFromCodeCoverage, bool $disableCodeCoverageIgnore, bool $failOnDeprecation, bool $failOnEmptyTestSuite, bool $failOnIncomplete, bool $failOnNotice, bool $failOnRisky, bool $failOnSkipped, bool $failOnWarning, bool $stopOnDefect, bool $stopOnDeprecation, bool $stopOnError, bool $stopOnFailure, bool $stopOnIncomplete, bool $stopOnNotice, bool $stopOnRisky, bool $stopOnSkipped, bool $stopOnWarning, bool $outputToStandardErrorStream, int|string $columns, bool $noExtensions, ?string $pharExtensionDirectory, array $extensionBootstrappers, bool $backupGlobals, bool $backupStaticProperties, bool $beStrictAboutChangesToGlobalState, bool $colors, bool $processIsolation, bool $enforceTimeLimit, int $defaultTimeLimit, int $timeoutForSmallTests, int $timeoutForMediumTests, int $timeoutForLargeTests, bool $reportUselessTests, bool $strictCoverage, bool $disallowTestOutput, bool $displayDetailsOnIncompleteTests, bool $displayDetailsOnSkippedTests, bool $displayDetailsOnTestsThatTriggerDeprecations, bool $displayDetailsOnTestsThatTriggerErrors, bool $displayDetailsOnTestsThatTriggerNotices, bool $displayDetailsOnTestsThatTriggerWarnings, bool $reverseDefectList, bool $requireCoverageMetadata, bool $noProgress, bool $noResults, bool $noOutput, int $executionOrder, int $executionOrderDefects, bool $resolveDependencies, ?string $logfileTeamcity, ?string $logfileJunit, ?string $logfileTestdoxHtml, ?string $logfileTestdoxText, ?string $logEventsText, ?string $logEventsVerboseText, bool $teamCityOutput, bool $testDoxOutput, ?array $testsCovering, ?array $testsUsing, ?string $filter, ?string $excludeFilter, ?array $groups, ?array $excludeGroups, int $randomOrderSeed, bool $includeUncoveredFiles, TestSuiteCollection $testSuite, string $includeTestSuite, string $excludeTestSuite, ?string $defaultTestSuite, array $testSuffixes, Php $php, bool $controlGarbageCollector, int $numberOfTestsBeforeGarbageCollection, ?string $generateBaseline, bool $debug)
150+
public function __construct(array $cliArguments, ?string $configurationFile, ?string $bootstrap, bool $cacheResult, ?string $cacheDirectory, ?string $coverageCacheDirectory, Source $source, string $testResultCacheFile, ?string $coverageClover, ?string $coverageCobertura, ?string $coverageCrap4j, int $coverageCrap4jThreshold, ?string $coverageHtml, int $coverageHtmlLowUpperBound, int $coverageHtmlHighLowerBound, string $coverageHtmlColorSuccessLow, string $coverageHtmlColorSuccessMedium, string $coverageHtmlColorSuccessHigh, string $coverageHtmlColorWarning, string $coverageHtmlColorDanger, ?string $coverageHtmlCustomCssFile, string $coverageHtmlTheme, ?string $coveragePhp, ?string $coverageText, bool $coverageTextShowUncoveredFiles, bool $coverageTextShowOnlySummary, ?string $coverageXml, bool $pathCoverage, bool $ignoreDeprecatedCodeUnitsFromCodeCoverage, bool $disableCodeCoverageIgnore, bool $failOnDeprecation, bool $failOnEmptyTestSuite, bool $failOnIncomplete, bool $failOnNotice, bool $failOnRisky, bool $failOnSkipped, bool $failOnWarning, bool $stopOnDefect, bool $stopOnDeprecation, bool $stopOnError, bool $stopOnFailure, bool $stopOnIncomplete, bool $stopOnNotice, bool $stopOnRisky, bool $stopOnSkipped, bool $stopOnWarning, bool $outputToStandardErrorStream, int|string $columns, bool $noExtensions, ?string $pharExtensionDirectory, array $extensionBootstrappers, bool $backupGlobals, bool $backupStaticProperties, bool $beStrictAboutChangesToGlobalState, bool $colors, bool $processIsolation, bool $enforceTimeLimit, int $defaultTimeLimit, int $timeoutForSmallTests, int $timeoutForMediumTests, int $timeoutForLargeTests, bool $reportUselessTests, bool $strictCoverage, bool $disallowTestOutput, bool $displayDetailsOnIncompleteTests, bool $displayDetailsOnSkippedTests, bool $displayDetailsOnTestsThatTriggerDeprecations, bool $displayDetailsOnTestsThatTriggerErrors, bool $displayDetailsOnTestsThatTriggerNotices, bool $displayDetailsOnTestsThatTriggerWarnings, bool $reverseDefectList, bool $requireCoverageMetadata, bool $noProgress, bool $noResults, bool $noOutput, int $executionOrder, int $executionOrderDefects, bool $resolveDependencies, ?string $logfileTeamcity, ?string $logfileJunit, ?string $logfileTestdoxHtml, ?string $logfileTestdoxText, ?string $logEventsText, ?string $logEventsVerboseText, bool $teamCityOutput, bool $testDoxOutput, ?array $testsCovering, ?array $testsUsing, ?string $filter, ?string $excludeFilter, ?array $groups, ?array $excludeGroups, int $randomOrderSeed, bool $includeUncoveredFiles, TestSuiteCollection $testSuite, string $includeTestSuite, string $excludeTestSuite, ?string $defaultTestSuite, array $testSuffixes, Php $php, bool $controlGarbageCollector, int $numberOfTestsBeforeGarbageCollection, ?string $generateBaseline, bool $debug)
150151
{
151152
$this->cliArguments = $cliArguments;
152153
$this->configurationFile = $configurationFile;
@@ -169,6 +170,7 @@ public function __construct(array $cliArguments, ?string $configurationFile, ?st
169170
$this->coverageHtmlColorWarning = $coverageHtmlColorWarning;
170171
$this->coverageHtmlColorDanger = $coverageHtmlColorDanger;
171172
$this->coverageHtmlCustomCssFile = $coverageHtmlCustomCssFile;
173+
$this->coverageHtmlTheme = $coverageHtmlTheme;
172174
$this->coveragePhp = $coveragePhp;
173175
$this->coverageText = $coverageText;
174176
$this->coverageTextShowUncoveredFiles = $coverageTextShowUncoveredFiles;
@@ -510,6 +512,11 @@ public function coverageHtmlColorDanger(): string
510512
return $this->coverageHtmlColorDanger;
511513
}
512514

515+
public function coverageHtmlTheme(): string
516+
{
517+
return $this->coverageHtmlTheme;
518+
}
519+
513520
/**
514521
* @psalm-assert-if-true !null $this->coverageHtmlCustomCssFile
515522
*/

src/TextUI/Configuration/Merger.php

+3
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ public function merge(CliConfiguration $cliConfiguration, XmlConfiguration $xmlC
263263
$coverageHtmlColorWarning = $defaultColors->warning();
264264
$coverageHtmlColorDanger = $defaultColors->danger();
265265
$coverageHtmlCustomCssFile = null;
266+
$coverageHtmlTheme = $defaultColors->theme();
266267
$coveragePhp = null;
267268
$coverageText = null;
268269
$coverageTextShowUncoveredFiles = false;
@@ -310,6 +311,7 @@ public function merge(CliConfiguration $cliConfiguration, XmlConfiguration $xmlC
310311
$coverageHtmlColorSuccessHigh = $xmlConfiguration->codeCoverage()->html()->colorSuccessHigh();
311312
$coverageHtmlColorWarning = $xmlConfiguration->codeCoverage()->html()->colorWarning();
312313
$coverageHtmlColorDanger = $xmlConfiguration->codeCoverage()->html()->colorDanger();
314+
$coverageHtmlTheme = $xmlConfiguration->codeCoverage()->html()->theme();
313315

314316
if ($xmlConfiguration->codeCoverage()->html()->hasCustomCssFile()) {
315317
$coverageHtmlCustomCssFile = $xmlConfiguration->codeCoverage()->html()->customCssFile();
@@ -750,6 +752,7 @@ public function merge(CliConfiguration $cliConfiguration, XmlConfiguration $xmlC
750752
$coverageHtmlColorWarning,
751753
$coverageHtmlColorDanger,
752754
$coverageHtmlCustomCssFile,
755+
$coverageHtmlTheme,
753756
$coveragePhp,
754757
$coverageText,
755758
$coverageTextShowUncoveredFiles,

src/TextUI/Configuration/Xml/CodeCoverage/Report/Html.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
private string $colorWarning;
2929
private string $colorDanger;
3030
private ?string $customCssFile;
31+
private string $theme;
3132

32-
public function __construct(Directory $target, int $lowUpperBound, int $highLowerBound, string $colorSuccessLow, string $colorSuccessMedium, string $colorSuccessHigh, string $colorWarning, string $colorDanger, ?string $customCssFile)
33+
public function __construct(Directory $target, int $lowUpperBound, int $highLowerBound, string $colorSuccessLow, string $colorSuccessMedium, string $colorSuccessHigh, string $colorWarning, string $colorDanger, ?string $customCssFile, string $theme = '')
3334
{
3435
$this->target = $target;
3536
$this->lowUpperBound = $lowUpperBound;
@@ -40,6 +41,7 @@ public function __construct(Directory $target, int $lowUpperBound, int $highLowe
4041
$this->colorWarning = $colorWarning;
4142
$this->colorDanger = $colorDanger;
4243
$this->customCssFile = $customCssFile;
44+
$this->theme = $theme;
4345
}
4446

4547
public function target(): Directory
@@ -82,6 +84,11 @@ public function colorDanger(): string
8284
return $this->colorDanger;
8385
}
8486

87+
public function theme(): string
88+
{
89+
return $this->theme;
90+
}
91+
8592
/**
8693
* @psalm-assert-if-true !null $this->customCssFile
8794
*/

src/TextUI/Configuration/Xml/Loader.php

+1
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ private function codeCoverage(string $filename, DOMXPath $xpath): CodeCoverage
428428
$this->getStringAttributeWithDefault($element, 'colorWarning', $defaultColors->warning()),
429429
$this->getStringAttributeWithDefault($element, 'colorDanger', $defaultColors->danger()),
430430
$this->getStringAttribute($element, 'customCssFile'),
431+
$this->getStringAttributeWithDefault($element, 'theme', $defaultColors->theme()),
431432
);
432433
}
433434

tests/unit/TextUI/Configuration/Xml/LoaderTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ public function testCodeCoverageConfigurationIsReadCorrectly(): void
211211
$this->assertSame($defaultColors->successHigh(), $codeCoverage->html()->colorSuccessHigh());
212212
$this->assertSame($defaultColors->warning(), $codeCoverage->html()->colorWarning());
213213
$this->assertSame($defaultColors->danger(), $codeCoverage->html()->colorDanger());
214+
$this->assertSame($defaultColors->theme(), $codeCoverage->html()->theme());
214215
$this->assertFalse($codeCoverage->html()->hasCustomCssFile());
215216

216217
$this->assertTrue($codeCoverage->hasPhp());

0 commit comments

Comments
 (0)