Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TestDox prettifying for class names with diacritics #4840

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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