Skip to content

Commit

Permalink
Fix TestDox prettifying for class names with diacritics
Browse files Browse the repository at this point in the history
  • Loading branch information
julienfalque authored and sebastianbergmann committed Dec 17, 2021
1 parent ba467f3 commit 134a4e7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 19 deletions.
20 changes: 1 addition & 19 deletions src/Util/TestDox/NamePrettifier.php
Expand Up @@ -26,7 +26,6 @@
use function is_object;
use function is_scalar;
use function is_string;
use function mb_strtolower;
use function ord;
use function preg_quote;
use function preg_replace;
Expand Down Expand Up @@ -109,24 +108,7 @@ public function prettifyTestClass(string $className): string
$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;
}
}
$result = preg_replace('/(?<=[[:lower:]])(?=[[:upper:]])/u', ' ', $className);

if ($fullyQualifiedName !== $className) {
return $result . ' (' . $fullyQualifiedName . ')';
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/Util/TestDox/NamePrettifierTest.php
Expand Up @@ -40,6 +40,8 @@ public function testTitleHasSensibleDefaults(): void
$this->assertEquals('Foo (Test\Foo)', $this->namePrettifier->prettifyTestClass('Test\FooTest'));
$this->assertEquals('Foo (Tests\Foo)', $this->namePrettifier->prettifyTestClass('Tests\FooTest'));
$this->assertEquals('Unnamed Tests', $this->namePrettifier->prettifyTestClass('TestTest'));
$this->assertEquals('Système Testé', $this->namePrettifier->prettifyTestClass('SystèmeTestéTest'));
$this->assertEquals('Expression Évaluée', $this->namePrettifier->prettifyTestClass('ExpressionÉvaluéeTest'));
}

public function testTestNameIsConvertedToASentence(): void
Expand Down

0 comments on commit 134a4e7

Please sign in to comment.