Skip to content

Commit e2b9b84

Browse files
Add support for dark mode to Colors value object
1 parent 19a9bf4 commit e2b9b84

5 files changed

Lines changed: 215 additions & 24 deletions

File tree

ChangeLog-14.0.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
1818
* The `<build>` element and its children of the XML report generated by `SebastianBergmann\CodeCoverage\Report\Xml\Facade` require the optional arguments to be passed to the `process()` method
1919
* The `TestSize` and `TestStatus` value objects are now enumerations
2020

21+
### Fixed
22+
23+
* Configuring colors for the HTML report no longer worked after support for dark mode was added
24+
2125
### Removed
2226

2327
* The `SebastianBergmann\CodeCoverage\Report\PHP` class was removed, use the new `SebastianBergmann\CodeCoverage\Serializer` class instead

src/Report/Html/Colors.php

Lines changed: 138 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,52 +17,181 @@
1717
final readonly class Colors
1818
{
1919
private string $successLow;
20+
private string $successLowDark;
2021
private string $successMedium;
22+
private string $successMediumDark;
2123
private string $successHigh;
24+
private string $successHighDark;
25+
private string $successBar;
26+
private string $successBarDark;
2227
private string $warning;
28+
private string $warningDark;
29+
private string $warningBar;
30+
private string $warningBarDark;
2331
private string $danger;
32+
private string $dangerDark;
33+
private string $dangerBar;
34+
private string $dangerBarDark;
35+
private string $breadcrumbs;
36+
private string $breadcrumbsDark;
2437

2538
public static function default(): self
2639
{
27-
return new self('#dff0d8', '#c3e3b5', '#99cb84', '#fcf8e3', '#f2dede');
40+
return new self(
41+
'#dff0d8',
42+
'#2d4431',
43+
'#c3e3b5',
44+
'#3c6051',
45+
'#99cb84',
46+
'#3d5c4e',
47+
'#28a745',
48+
'#1f8135',
49+
'#fcf8e3',
50+
'#3e3408',
51+
'#ffc107',
52+
'#c19406',
53+
'#f2dede',
54+
'#42221e',
55+
'#dc3545',
56+
'#a62633',
57+
'var(--bs-gray-200)',
58+
'var(--bs-gray-800)',
59+
);
2860
}
2961

30-
public static function from(string $successLow, string $successMedium, string $successHigh, string $warning, string $danger): self
62+
public static function from(string $successLow, string $successLowDark, string $successMedium, string $successMediumDark, string $successHigh, string $successHighDark, string $successBar, string $successBarDark, string $warning, string $warningDark, string $warningBar, string $warningBarDark, string $danger, string $dangerDark, string $dangerBar, string $dangerBarDark, string $breadcrumbs, string $breadcrumbsDark): self
3163
{
32-
return new self($successLow, $successMedium, $successHigh, $warning, $danger);
64+
return new self(
65+
$successLow,
66+
$successLowDark,
67+
$successMedium,
68+
$successMediumDark,
69+
$successHigh,
70+
$successHighDark,
71+
$successBar,
72+
$successBarDark,
73+
$warning,
74+
$warningDark,
75+
$warningBar,
76+
$warningBarDark,
77+
$danger,
78+
$dangerDark,
79+
$dangerBar,
80+
$dangerBarDark,
81+
$breadcrumbs,
82+
$breadcrumbsDark,
83+
);
3384
}
3485

35-
private function __construct(string $successLow, string $successMedium, string $successHigh, string $warning, string $danger)
86+
private function __construct(string $successLow, string $successLowDark, string $successMedium, string $successMediumDark, string $successHigh, string $successHighDark, string $successBar, string $successBarDark, string $warning, string $warningDark, string $warningBar, string $warningBarDark, string $danger, string $dangerDark, string $dangerBar, string $dangerBarDark, string $breadcrumbs, string $breadcrumbsDark)
3687
{
37-
$this->successLow = $successLow;
38-
$this->successMedium = $successMedium;
39-
$this->successHigh = $successHigh;
40-
$this->warning = $warning;
41-
$this->danger = $danger;
88+
$this->successLow = $successLow;
89+
$this->successLowDark = $successLowDark;
90+
$this->successMedium = $successMedium;
91+
$this->successMediumDark = $successMediumDark;
92+
$this->successHigh = $successHigh;
93+
$this->successHighDark = $successHighDark;
94+
$this->successBar = $successBar;
95+
$this->successBarDark = $successBarDark;
96+
$this->warning = $warning;
97+
$this->warningDark = $warningDark;
98+
$this->warningBar = $warningBar;
99+
$this->warningBarDark = $warningBarDark;
100+
$this->danger = $danger;
101+
$this->dangerDark = $dangerDark;
102+
$this->dangerBar = $dangerBar;
103+
$this->dangerBarDark = $dangerBarDark;
104+
$this->breadcrumbs = $breadcrumbs;
105+
$this->breadcrumbsDark = $breadcrumbsDark;
42106
}
43107

44108
public function successLow(): string
45109
{
46110
return $this->successLow;
47111
}
48112

113+
public function successLowDark(): string
114+
{
115+
return $this->successLowDark;
116+
}
117+
49118
public function successMedium(): string
50119
{
51120
return $this->successMedium;
52121
}
53122

123+
public function successMediumDark(): string
124+
{
125+
return $this->successMediumDark;
126+
}
127+
54128
public function successHigh(): string
55129
{
56130
return $this->successHigh;
57131
}
58132

133+
public function successHighDark(): string
134+
{
135+
return $this->successHighDark;
136+
}
137+
138+
public function successBar(): string
139+
{
140+
return $this->successBar;
141+
}
142+
143+
public function successBarDark(): string
144+
{
145+
return $this->successBarDark;
146+
}
147+
59148
public function warning(): string
60149
{
61150
return $this->warning;
62151
}
63152

153+
public function warningDark(): string
154+
{
155+
return $this->warningDark;
156+
}
157+
158+
public function warningBar(): string
159+
{
160+
return $this->warningBar;
161+
}
162+
163+
public function warningBarDark(): string
164+
{
165+
return $this->warningBarDark;
166+
}
167+
64168
public function danger(): string
65169
{
66170
return $this->danger;
67171
}
172+
173+
public function dangerDark(): string
174+
{
175+
return $this->dangerDark;
176+
}
177+
178+
public function dangerBar(): string
179+
{
180+
return $this->dangerBar;
181+
}
182+
183+
public function dangerBarDark(): string
184+
{
185+
return $this->dangerBarDark;
186+
}
187+
188+
public function breadcrumbs(): string
189+
{
190+
return $this->breadcrumbs;
191+
}
192+
193+
public function breadcrumbsDark(): string
194+
{
195+
return $this->breadcrumbsDark;
196+
}
68197
}

src/Report/Html/Facade.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,24 @@ private function renderCss(string $target): void
123123

124124
$template->setVar(
125125
[
126-
'success-low' => $this->colors->successLow(),
127-
'success-medium' => $this->colors->successMedium(),
128-
'success-high' => $this->colors->successHigh(),
129-
'warning' => $this->colors->warning(),
130-
'danger' => $this->colors->danger(),
126+
'breadcrumbs' => $this->colors->breadcrumbs(),
127+
'breadcrumbs-dark' => $this->colors->breadcrumbsDark(),
128+
'success-bar' => $this->colors->successBar(),
129+
'success-bar-dark' => $this->colors->successBarDark(),
130+
'success-high' => $this->colors->successHigh(),
131+
'success-high-dark' => $this->colors->successHighDark(),
132+
'success-medium' => $this->colors->successMedium(),
133+
'success-medium-dark' => $this->colors->successMediumDark(),
134+
'success-low' => $this->colors->successLow(),
135+
'success-low-dark' => $this->colors->successLowDark(),
136+
'warning' => $this->colors->warning(),
137+
'warning-dark' => $this->colors->warningDark(),
138+
'warning-bar' => $this->colors->warningBar(),
139+
'warning-bar-dark' => $this->colors->warningBarDark(),
140+
'danger' => $this->colors->danger(),
141+
'danger-dark' => $this->colors->dangerDark(),
142+
'danger-bar' => $this->colors->dangerBar(),
143+
'danger-bar-dark' => $this->colors->dangerBarDark(),
131144
],
132145
);
133146

src/Report/Html/Renderer/Template/css/style.css

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
color-scheme: light dark;
55

66
/* PHPUnit light/dark colors */
7-
--phpunit-breadcrumbs: light-dark(var(--bs-gray-200), var(--bs-gray-800));
8-
--phpunit-success-bar: light-dark(#28a745 ,#1f8135);
9-
--phpunit-success-high: light-dark(#99cb84, #3d5c4e);
10-
--phpunit-success-medium: light-dark(#c3e3b5,#3c6051);
11-
--phpunit-success-low: light-dark(#dff0d8, #2d4431);
12-
--phpunit-warning: light-dark(#fcf8e3, #3e3408);
13-
--phpunit-warning-bar: light-dark(#ffc107 ,#c19406);
14-
--phpunit-danger: light-dark(#f2dede, #42221e);
15-
--phpunit-danger-bar: light-dark(#dc3545, #a62633);
7+
--phpunit-breadcrumbs: light-dark({{breadcrumbs}}, {{breadcrumbs-dark}});
8+
--phpunit-success-bar: light-dark({{success-bar}}, {{success-bar-dark}});
9+
--phpunit-success-high: light-dark({{success-high}}, {{success-high-dark}});
10+
--phpunit-success-medium: light-dark({{success-medium}}, {{success-medium-dark}});
11+
--phpunit-success-low: light-dark({{success-low}}, {{success-low-dark}});
12+
--phpunit-warning: light-dark({{warning}}, {{warning-dark}});
13+
--phpunit-warning-bar: light-dark({{warning-bar}}, {{warning-bar-dark}});
14+
--phpunit-danger: light-dark({{danger}}, {{danger-dark}});
15+
--phpunit-danger-bar: light-dark({{danger-bar}}, {{danger-bar-dark}});
1616

1717
/* Bootstrap v5.3 default colors (light, dark) */
1818
--bs-body-bg-rgb: 255, 255, 255;

tests/tests/Report/Html/ColorsTest.php

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,65 @@ public function testCanBeCreatedFromDefaults(): void
2222
$colors = Colors::default();
2323

2424
$this->assertSame('#dff0d8', $colors->successLow());
25+
$this->assertSame('#2d4431', $colors->successLowDark());
2526
$this->assertSame('#c3e3b5', $colors->successMedium());
27+
$this->assertSame('#3c6051', $colors->successMediumDark());
2628
$this->assertSame('#99cb84', $colors->successHigh());
29+
$this->assertSame('#3d5c4e', $colors->successHighDark());
30+
$this->assertSame('#28a745', $colors->successBar());
31+
$this->assertSame('#1f8135', $colors->successBarDark());
2732
$this->assertSame('#fcf8e3', $colors->warning());
33+
$this->assertSame('#3e3408', $colors->warningDark());
34+
$this->assertSame('#ffc107', $colors->warningBar());
35+
$this->assertSame('#c19406', $colors->warningBarDark());
2836
$this->assertSame('#f2dede', $colors->danger());
37+
$this->assertSame('#42221e', $colors->dangerDark());
38+
$this->assertSame('#dc3545', $colors->dangerBar());
39+
$this->assertSame('#a62633', $colors->dangerBarDark());
40+
$this->assertSame('var(--bs-gray-200)', $colors->breadcrumbs());
41+
$this->assertSame('var(--bs-gray-800)', $colors->breadcrumbsDark());
2942
}
3043

3144
public function testCanBeCreatedFromCustomValues(): void
3245
{
33-
$colors = Colors::from('successLow', 'successMedium', 'successHigh', 'warning', 'danger');
46+
$colors = Colors::from(
47+
'successLow',
48+
'successLowDark',
49+
'successMedium',
50+
'successMediumDark',
51+
'successHigh',
52+
'successHighDark',
53+
'successBar',
54+
'successBarDark',
55+
'warning',
56+
'warningDark',
57+
'warningBar',
58+
'warningBarDark',
59+
'danger',
60+
'dangerDark',
61+
'dangerBar',
62+
'dangerBarDark',
63+
'breadcrumbs',
64+
'breadcrumbsDark',
65+
);
3466

3567
$this->assertSame('successLow', $colors->successLow());
68+
$this->assertSame('successLowDark', $colors->successLowDark());
3669
$this->assertSame('successMedium', $colors->successMedium());
70+
$this->assertSame('successMediumDark', $colors->successMediumDark());
3771
$this->assertSame('successHigh', $colors->successHigh());
72+
$this->assertSame('successHighDark', $colors->successHighDark());
73+
$this->assertSame('successBar', $colors->successBar());
74+
$this->assertSame('successBarDark', $colors->successBarDark());
3875
$this->assertSame('warning', $colors->warning());
76+
$this->assertSame('warningDark', $colors->warningDark());
77+
$this->assertSame('warningBar', $colors->warningBar());
78+
$this->assertSame('warningBarDark', $colors->warningBarDark());
3979
$this->assertSame('danger', $colors->danger());
80+
$this->assertSame('dangerDark', $colors->dangerDark());
81+
$this->assertSame('dangerBar', $colors->dangerBar());
82+
$this->assertSame('dangerBarDark', $colors->dangerBarDark());
83+
$this->assertSame('breadcrumbs', $colors->breadcrumbs());
84+
$this->assertSame('breadcrumbsDark', $colors->breadcrumbsDark());
4085
}
4186
}

0 commit comments

Comments
 (0)