Skip to content

Commit

Permalink
Adds theme support to code coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
gammamatrix committed May 8, 2024
1 parent e41231b commit 36bbd10
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 15 deletions.
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.

1 change: 1 addition & 0 deletions phpunit.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@
<xs:attribute name="colorWarning" type="xs:string" default="#fcf8e3"/>
<xs:attribute name="colorDanger" type="xs:string" default="#f2dede"/>
<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

0 comments on commit 36bbd10

Please sign in to comment.