Skip to content

Commit 7964343

Browse files
Backport TestDox HTML improvements
1 parent 31a21e7 commit 7964343

File tree

3 files changed

+67
-21
lines changed

3 files changed

+67
-21
lines changed

ChangeLog-9.6.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes of the PHPUnit 9.6 release series are documented in this fil
44

55
## [9.6.5] - 2023-MM-DD
66

7+
### Changed
8+
9+
* Backported the HTML and CSS improvements made to the `--testdox-html` from PHPUnit 10
10+
711
### Fixed
812

913
* [#5205](https://github.com/sebastianbergmann/phpunit/issues/5205): Wrong default value for optional parameter of `PHPUnit\Util\Test::parseTestMethodAnnotations()` causes `ReflectionException`

src/Util/TestDox/HtmlResultPrinter.php

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,46 @@ final class HtmlResultPrinter extends ResultPrinter
3131
text-rendering: optimizeLegibility;
3232
font-variant-ligatures: common-ligatures;
3333
font-kerning: normal;
34-
margin-left: 2em;
35-
background-color: #ffffff;
36-
color: #000000;
34+
margin-left: 2rem;
35+
background-color: #fff;
36+
color: #000;
3737
}
3838
3939
body > ul > li {
4040
font-family: Source Serif Pro, PT Sans, Trebuchet MS, Helvetica, Arial;
41-
font-size: 2em;
41+
font-size: larger;
4242
}
4343
4444
h2 {
4545
font-family: Tahoma, Helvetica, Arial;
46-
font-size: 3em;
46+
font-size: larger;
47+
margin: 0;
48+
padding: 0.5rem 0;
4749
}
4850
4951
ul {
5052
list-style: none;
51-
margin-bottom: 1em;
53+
margin: 0;
54+
padding: 0;
55+
margin-bottom: 2rem;
56+
padding-left: 1rem;
57+
text-indent: -1rem;
58+
}
59+
60+
.success:before {
61+
color: #4e9a06;
62+
content: '✓';
63+
padding-right: 0.5rem;
64+
}
65+
66+
.defect {
67+
color: #a40000;
68+
}
69+
70+
.defect:before {
71+
color: #a40000;
72+
content: '✗';
73+
padding-right: 0.5rem;
5274
}
5375
</style>
5476
</head>
@@ -60,7 +82,7 @@ final class HtmlResultPrinter extends ResultPrinter
6082
*/
6183
private const CLASS_HEADER = <<<'EOT'
6284
63-
<h2 id="%s">%s</h2>
85+
<h2>%s</h2>
6486
<ul>
6587

6688
EOT;
@@ -101,7 +123,6 @@ protected function startClass(string $name): void
101123
$this->write(
102124
sprintf(
103125
self::CLASS_HEADER,
104-
$name,
105126
$this->currentTestClassPrettified
106127
)
107128
);
@@ -114,9 +135,8 @@ protected function onTest(string $name, bool $success = true): void
114135
{
115136
$this->write(
116137
sprintf(
117-
" <li style=\"color: %s;\">%s %s</li>\n",
118-
$success ? '#555753' : '#ef2929',
119-
$success ? '' : '',
138+
" <li class=\"%s\">%s</li>\n",
139+
$success ? 'success' : 'defect',
120140
$name
121141
)
122142
);

tests/end-to-end/logging/testdox-html.phpt

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,34 +23,56 @@ PHPUnit %s by Sebastian Bergmann and contributors.
2323
text-rendering: optimizeLegibility;
2424
font-variant-ligatures: common-ligatures;
2525
font-kerning: normal;
26-
margin-left: 2em;
27-
background-color: #ffffff;
28-
color: #000000;
26+
margin-left: 2rem;
27+
background-color: #fff;
28+
color: #000;
2929
}
3030

3131
body > ul > li {
3232
font-family: Source Serif Pro, PT Sans, Trebuchet MS, Helvetica, Arial;
33-
font-size: 2em;
33+
font-size: larger;
3434
}
3535

3636
h2 {
3737
font-family: Tahoma, Helvetica, Arial;
38-
font-size: 3em;
38+
font-size: larger;
39+
margin: 0;
40+
padding: 0.5rem 0;
3941
}
4042

4143
ul {
4244
list-style: none;
43-
margin-bottom: 1em;
45+
margin: 0;
46+
padding: 0;
47+
margin-bottom: 2rem;
48+
padding-left: 1rem;
49+
text-indent: -1rem;
50+
}
51+
52+
.success:before {
53+
color: #4e9a06;
54+
content: '✓';
55+
padding-right: 0.5rem;
56+
}
57+
58+
.defect {
59+
color: #a40000;
60+
}
61+
62+
.defect:before {
63+
color: #a40000;
64+
content: '✗';
65+
padding-right: 0.5rem;
4466
}
4567
</style>
4668
</head>
4769
<body>
4870

49-
<h2 id="PHPUnit\TestFixture\BankAccountTest">Bank Account (PHPUnit\TestFixture\BankAccount)</h2>
71+
<h2>Bank Account (PHPUnit\TestFixture\BankAccount)</h2>
5072
<ul>
51-
... 3 / 3 (100%) <li style="color: #555753;">✓ Balance is initially zero</li>
52-
<li style="color: #555753;">✓ Balance cannot become negative</li>
53-
<li style="color: #555753;">✓ Balance cannot become negative</li>
73+
... 3 / 3 (100%) <li class="success">Balance is initially zero</li>
74+
<li class="success">Balance cannot become negative</li>
75+
<li class="success">Balance cannot become negative</li>
5476
</ul>
5577
</body>
5678
</html>

0 commit comments

Comments
 (0)