Skip to content

Adds theme support to code coverage. #5833

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

Open
wants to merge 3 commits into
base: main
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
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
"security": "https://github.com/sebastianbergmann/phpunit/security/policy"
},
"prefer-stable": true,
"repositories": [
{
"type": "vcs",
"url": "https://github.com/gammamatrix/php-code-coverage.git"
}
],
"require": {
"php": ">=8.2",
"ext-dom": "*",
Expand All @@ -32,7 +38,7 @@
"myclabs/deep-copy": "^1.10.1",
"phar-io/manifest": "^2.0.3",
"phar-io/version": "^3.0.2",
"phpunit/php-code-coverage": "^11.0",
"phpunit/php-code-coverage": "dev-update-to-bootstrap-5",
"phpunit/php-file-iterator": "^5.0",
"phpunit/php-invoker": "^5.0",
"phpunit/php-text-template": "^4.0",
Expand Down
31 changes: 19 additions & 12 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions phpunit.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,13 @@
<xs:attribute name="outputDirectory" type="xs:anyURI" use="required"/>
<xs:attribute name="lowUpperBound" type="xs:integer" default="50"/>
<xs:attribute name="highLowerBound" type="xs:integer" default="90"/>
<xs:attribute name="colorSuccessLow" type="xs:string" default="#dff0d8"/>
<xs:attribute name="colorSuccessMedium" type="xs:string" default="#c3e3b5"/>
<xs:attribute name="colorSuccessHigh" type="xs:string" default="#99cb84"/>
<xs:attribute name="colorWarning" type="xs:string" default="#fcf8e3"/>
<xs:attribute name="colorDanger" type="xs:string" default="#f2dede"/>
<xs:attribute name="colorSuccessLow" type="xs:string"/>
<xs:attribute name="colorSuccessMedium" type="xs:string"/>
<xs:attribute name="colorSuccessHigh" type="xs:string"/>
<xs:attribute name="colorWarning" type="xs:string"/>
<xs:attribute name="colorDanger" type="xs:string"/>
<xs:attribute name="customCssFile" type="xs:string"/>
<xs:attribute name="theme" type="xs:string"/>
</xs:complexType>
<xs:complexType name="coverageReportTextType">
<xs:attribute name="outputFile" type="xs:anyURI" use="required"/>
Expand Down
1 change: 1 addition & 0 deletions src/Runner/CodeCoverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ public function generateReports(Printer $printer, Configuration $configuration):
$configuration->coverageHtmlColorSuccessHigh(),
$configuration->coverageHtmlColorWarning(),
$configuration->coverageHtmlColorDanger(),
$configuration->coverageHtmlTheme(),
),
Thresholds::from(
$configuration->coverageHtmlLowUpperBound(),
Expand Down
9 changes: 8 additions & 1 deletion src/TextUI/Configuration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
private string $coverageHtmlColorWarning;
private string $coverageHtmlColorDanger;
private ?string $coverageHtmlCustomCssFile;
private string $coverageHtmlTheme;
private ?string $coveragePhp;
private ?string $coverageText;
private bool $coverageTextShowUncoveredFiles;
Expand Down Expand Up @@ -146,7 +147,7 @@
* @psalm-param non-empty-list<non-empty-string> $testSuffixes
* @psalm-param list<array{className: class-string, parameters: array<string, string>}> $extensionBootstrappers
*/
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)
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)
{
$this->cliArguments = $cliArguments;
$this->configurationFile = $configurationFile;
Expand All @@ -169,6 +170,7 @@ public function __construct(array $cliArguments, ?string $configurationFile, ?st
$this->coverageHtmlColorWarning = $coverageHtmlColorWarning;
$this->coverageHtmlColorDanger = $coverageHtmlColorDanger;
$this->coverageHtmlCustomCssFile = $coverageHtmlCustomCssFile;
$this->coverageHtmlTheme = $coverageHtmlTheme;
$this->coveragePhp = $coveragePhp;
$this->coverageText = $coverageText;
$this->coverageTextShowUncoveredFiles = $coverageTextShowUncoveredFiles;
Expand Down Expand Up @@ -510,6 +512,11 @@ public function coverageHtmlColorDanger(): string
return $this->coverageHtmlColorDanger;
}

public function coverageHtmlTheme(): string
{
return $this->coverageHtmlTheme;
}

/**
* @psalm-assert-if-true !null $this->coverageHtmlCustomCssFile
*/
Expand Down
3 changes: 3 additions & 0 deletions src/TextUI/Configuration/Merger.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ public function merge(CliConfiguration $cliConfiguration, XmlConfiguration $xmlC
$coverageHtmlColorWarning = $defaultColors->warning();
$coverageHtmlColorDanger = $defaultColors->danger();
$coverageHtmlCustomCssFile = null;
$coverageHtmlTheme = $defaultColors->theme();
$coveragePhp = null;
$coverageText = null;
$coverageTextShowUncoveredFiles = false;
Expand Down Expand Up @@ -310,6 +311,7 @@ public function merge(CliConfiguration $cliConfiguration, XmlConfiguration $xmlC
$coverageHtmlColorSuccessHigh = $xmlConfiguration->codeCoverage()->html()->colorSuccessHigh();
$coverageHtmlColorWarning = $xmlConfiguration->codeCoverage()->html()->colorWarning();
$coverageHtmlColorDanger = $xmlConfiguration->codeCoverage()->html()->colorDanger();
$coverageHtmlTheme = $xmlConfiguration->codeCoverage()->html()->theme();

if ($xmlConfiguration->codeCoverage()->html()->hasCustomCssFile()) {
$coverageHtmlCustomCssFile = $xmlConfiguration->codeCoverage()->html()->customCssFile();
Expand Down Expand Up @@ -750,6 +752,7 @@ public function merge(CliConfiguration $cliConfiguration, XmlConfiguration $xmlC
$coverageHtmlColorWarning,
$coverageHtmlColorDanger,
$coverageHtmlCustomCssFile,
$coverageHtmlTheme,
$coveragePhp,
$coverageText,
$coverageTextShowUncoveredFiles,
Expand Down
9 changes: 8 additions & 1 deletion src/TextUI/Configuration/Xml/CodeCoverage/Report/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
private string $colorWarning;
private string $colorDanger;
private ?string $customCssFile;
private string $theme;

public function __construct(Directory $target, int $lowUpperBound, int $highLowerBound, string $colorSuccessLow, string $colorSuccessMedium, string $colorSuccessHigh, string $colorWarning, string $colorDanger, ?string $customCssFile)
public function __construct(Directory $target, int $lowUpperBound, int $highLowerBound, string $colorSuccessLow, string $colorSuccessMedium, string $colorSuccessHigh, string $colorWarning, string $colorDanger, ?string $customCssFile, string $theme = '')
{
$this->target = $target;
$this->lowUpperBound = $lowUpperBound;
Expand All @@ -40,6 +41,7 @@ public function __construct(Directory $target, int $lowUpperBound, int $highLowe
$this->colorWarning = $colorWarning;
$this->colorDanger = $colorDanger;
$this->customCssFile = $customCssFile;
$this->theme = $theme;
}

public function target(): Directory
Expand Down Expand Up @@ -82,6 +84,11 @@ public function colorDanger(): string
return $this->colorDanger;
}

public function theme(): string
{
return $this->theme;
}

/**
* @psalm-assert-if-true !null $this->customCssFile
*/
Expand Down
1 change: 1 addition & 0 deletions src/TextUI/Configuration/Xml/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ private function codeCoverage(string $filename, DOMXPath $xpath): CodeCoverage
$this->getStringAttributeWithDefault($element, 'colorWarning', $defaultColors->warning()),
$this->getStringAttributeWithDefault($element, 'colorDanger', $defaultColors->danger()),
$this->getStringAttribute($element, 'customCssFile'),
$this->getStringAttributeWithDefault($element, 'theme', $defaultColors->theme()),
);
}

Expand Down
1 change: 1 addition & 0 deletions tests/unit/TextUI/Configuration/Xml/LoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ public function testCodeCoverageConfigurationIsReadCorrectly(): void
$this->assertSame($defaultColors->successHigh(), $codeCoverage->html()->colorSuccessHigh());
$this->assertSame($defaultColors->warning(), $codeCoverage->html()->colorWarning());
$this->assertSame($defaultColors->danger(), $codeCoverage->html()->colorDanger());
$this->assertSame($defaultColors->theme(), $codeCoverage->html()->theme());
$this->assertFalse($codeCoverage->html()->hasCustomCssFile());

$this->assertTrue($codeCoverage->hasPhp());
Expand Down