diff --git a/ChangeLog-8.3.md b/ChangeLog-8.3.md index 087d02557c9..75f80ad0d2c 100644 --- a/ChangeLog-8.3.md +++ b/ChangeLog-8.3.md @@ -6,6 +6,7 @@ All notable changes of the PHPUnit 8.3 release series are documented in this fil ### Added +* Implemented [#3741](https://github.com/sebastianbergmann/phpunit/issues/3741): Format class names as well as method names in testdox output * Implemented [#3748](https://github.com/sebastianbergmann/phpunit/issues/3748): Add option to sort tests based on information from `@small`, `@medium`, and `@large` * Added `TestCase::getActualOutputForAssertion()` as a wrapper for `TestCase::getActualOutput()` to prevent a test being marked as risky when it prints output and that output is not expected using `TestCase::expectOutputString()` or `TestCase::expectOutputRegEx()` diff --git a/src/Util/TestDox/NamePrettifier.php b/src/Util/TestDox/NamePrettifier.php index d04005f2e5c..fa2b1c2b449 100644 --- a/src/Util/TestDox/NamePrettifier.php +++ b/src/Util/TestDox/NamePrettifier.php @@ -49,20 +49,47 @@ public function prettifyTestClass(string $className): string } catch (UtilException $e) { } - $result = $className; + $parts = \explode('\\', $className); + $className = \array_pop($parts); if (\substr($className, -1 * \strlen('Test')) === 'Test') { - $result = \substr($result, 0, \strripos($result, 'Test')); + $className = \substr($className, 0, \strlen($className) - \strlen('Test')); } if (\strpos($className, 'Tests') === 0) { - $result = \substr($result, \strlen('Tests')); + $className = \substr($className, \strlen('Tests')); } elseif (\strpos($className, 'Test') === 0) { - $result = \substr($result, \strlen('Test')); + $className = \substr($className, \strlen('Test')); } - if ($result[0] === '\\') { - $result = \substr($result, 1); + if (!empty($parts)) { + $parts[] = $className; + $fullyQualifiedName = \implode('\\', $parts); + } else { + $fullyQualifiedName = $className; + } + + $result = ''; + $wasLowerCase = false; + + foreach (\range(0, \strlen($className) - 1) as $i) { + $isLowerCase = \mb_strtolower($className[$i], 'UTF-8') === $className[$i]; + + if ($wasLowerCase && !$isLowerCase) { + $result .= ' '; + } + + $result .= $className[$i]; + + if ($isLowerCase) { + $wasLowerCase = true; + } else { + $wasLowerCase = false; + } + } + + if ($fullyQualifiedName !== $className) { + return $result . ' (' . $fullyQualifiedName . ')'; } return $result; @@ -153,10 +180,9 @@ public function prettifyTestMethod(string $name): string return \trim(\str_replace('_', ' ', $name)); } - $max = \strlen($name); $wasNumeric = false; - for ($i = 0; $i < $max; $i++) { + foreach (\range(0, \strlen($name) - 1) as $i) { if ($i > 0 && \ord($name[$i]) >= 65 && \ord($name[$i]) <= 90) { $buffer .= ' ' . \strtolower($name[$i]); } else { diff --git a/tests/end-to-end/defaulttestsuite-using-testsuite.phpt b/tests/end-to-end/defaulttestsuite-using-testsuite.phpt index d959356a76b..4c849e5e5f3 100644 --- a/tests/end-to-end/defaulttestsuite-using-testsuite.phpt +++ b/tests/end-to-end/defaulttestsuite-using-testsuite.phpt @@ -13,7 +13,7 @@ PHPUnit\TextUI\Command::main(); --EXPECTF-- PHPUnit %s by Sebastian Bergmann and contributors. -DummyFoo +Dummy Foo ✔ Foo equals foo Time: %s, Memory: %s diff --git a/tests/end-to-end/defaulttestsuite.phpt b/tests/end-to-end/defaulttestsuite.phpt index 2237f418885..0c092811485 100644 --- a/tests/end-to-end/defaulttestsuite.phpt +++ b/tests/end-to-end/defaulttestsuite.phpt @@ -11,7 +11,7 @@ PHPUnit\TextUI\Command::main(); --EXPECTF-- PHPUnit %s by Sebastian Bergmann and contributors. -DummyBar +Dummy Bar ✔ Bar equals bar Time: %s, Memory: %s diff --git a/tests/end-to-end/group.phpt b/tests/end-to-end/group.phpt index 6cfc0399588..7468366acb5 100644 --- a/tests/end-to-end/group.phpt +++ b/tests/end-to-end/group.phpt @@ -14,7 +14,7 @@ PHPUnit\TextUI\Command::main(); --EXPECTF-- PHPUnit %s by Sebastian Bergmann and contributors. -NumericGroupAnnotation +Numeric Group Annotation ✔ Empty test for @ticket numeric annotation values ✔ Empty test for @group numeric annotation values diff --git a/tests/end-to-end/loggers/_files/raw_output_StatusTest.txt b/tests/end-to-end/loggers/_files/raw_output_StatusTest.txt index d0a5dfcccd4..88e95c4e1ba 100644 --- a/tests/end-to-end/loggers/_files/raw_output_StatusTest.txt +++ b/tests/end-to-end/loggers/_files/raw_output_StatusTest.txt @@ -3,7 +3,7 @@ PHPUnit %s Sebastian Bergmann and contributors. Runtime: %s Configuration: %stests%ebasic%econfiguration.basic.xml -PHPUnit\SelfTest\Basic\SetUpBeforeClass +Set Up Before Class (PHPUnit\SelfTest\Basic\SetUpBeforeClass) ✘ One  %f ms ┐ ├ Exception: forcing an Exception in setUpBeforeClass() @@ -18,7 +18,7 @@ Configuration: %stests%ebasic%econfiguration.basic.xml ╵ %stests%ebasic%eunit%eSetUpBeforeClassTest.php:31 ┴ -PHPUnit\SelfTest\Basic\SetUp +Set Up (PHPUnit\SelfTest\Basic\SetUp) ✘ One with set up exception  %f ms ┐ ├ RuntimeException: throw exception in setUp @@ -115,7 +115,7 @@ Configuration: %stests%ebasic%econfiguration.basic.xml ╵ %stests%ebasic%eunit%eStatusTest.php:%d ┴ -PHPUnit\SelfTest\Basic\TearDownAfterClass +Tear Down After Class (PHPUnit\SelfTest\Basic\TearDownAfterClass) ✔ One  %f ms ✔ Two  %f ms ✘ Tear down after class  0 ms diff --git a/tests/end-to-end/loggers/testdox-exclude-group.phpt b/tests/end-to-end/loggers/testdox-exclude-group.phpt index 7b105a267e0..2a8f43ad7e7 100644 --- a/tests/end-to-end/loggers/testdox-exclude-group.phpt +++ b/tests/end-to-end/loggers/testdox-exclude-group.phpt @@ -18,7 +18,7 @@ PHPUnit\TextUI\Command::main(); --EXPECTF-- PHPUnit %s by Sebastian Bergmann and contributors. -.DoxGroup +.Dox Group . 2 / 2 (100%) [x] Two diff --git a/tests/end-to-end/loggers/testdox-group.phpt b/tests/end-to-end/loggers/testdox-group.phpt index 05ba3960990..1bc90d0e66a 100644 --- a/tests/end-to-end/loggers/testdox-group.phpt +++ b/tests/end-to-end/loggers/testdox-group.phpt @@ -18,7 +18,7 @@ PHPUnit\TextUI\Command::main(); --EXPECTF-- PHPUnit %s by Sebastian Bergmann and contributors. -DoxGroup +Dox Group .. 2 / 2 (100%) [x] One diff --git a/tests/end-to-end/loggers/testdox-html.phpt b/tests/end-to-end/loggers/testdox-html.phpt index cc6dc4e1078..b1af6389397 100644 --- a/tests/end-to-end/loggers/testdox-html.phpt +++ b/tests/end-to-end/loggers/testdox-html.phpt @@ -46,7 +46,7 @@ PHPUnit %s by Sebastian Bergmann and contributors. -

BankAccount

+

Bank Account