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 committed Dec 16, 2021
1 parent ba467f3 commit b891638
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 b891638

Please sign in to comment.