Skip to content

Commit 8af693c

Browse files
Merge branch '11.5' into 12.2
2 parents 922f000 + 155f2f6 commit 8af693c

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

src/Event/Value/Test/TestDoxBuilder.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
*
1818
* @internal This class is not covered by the backward compatibility promise for PHPUnit
1919
*/
20-
final readonly class TestDoxBuilder
20+
final class TestDoxBuilder
2121
{
22+
private static ?NamePrettifier $namePrettifier = null;
23+
2224
public static function fromTestCase(TestCase $testCase): TestDox
2325
{
24-
$prettifier = new NamePrettifier;
26+
$prettifier = self::namePrettifier();
2527

2628
return new TestDox(
2729
$prettifier->prettifyTestClassName($testCase::class),
@@ -36,7 +38,7 @@ public static function fromTestCase(TestCase $testCase): TestDox
3638
*/
3739
public static function fromClassNameAndMethodName(string $className, string $methodName): TestDox
3840
{
39-
$prettifier = new NamePrettifier;
41+
$prettifier = self::namePrettifier();
4042

4143
$prettifiedMethodName = $prettifier->prettifyTestMethodName($methodName);
4244

@@ -46,4 +48,13 @@ public static function fromClassNameAndMethodName(string $className, string $met
4648
$prettifiedMethodName,
4749
);
4850
}
51+
52+
private static function namePrettifier(): NamePrettifier
53+
{
54+
if (self::$namePrettifier === null) {
55+
self::$namePrettifier = new NamePrettifier;
56+
}
57+
58+
return self::$namePrettifier;
59+
}
4960
}

src/Logging/TestDox/NamePrettifier.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ final class NamePrettifier
5757
/**
5858
* @var array<string, int>
5959
*/
60-
private static array $strings = [];
60+
private array $strings = [];
6161

6262
/**
6363
* @param class-string $className
@@ -118,10 +118,10 @@ public function prettifyTestMethodName(string $name): string
118118

119119
$string = rtrim($name, '0123456789');
120120

121-
if (array_key_exists($string, self::$strings)) {
121+
if (array_key_exists($string, $this->strings)) {
122122
$name = $string;
123123
} elseif ($string === $name) {
124-
self::$strings[$string] = 1;
124+
$this->strings[$string] = 1;
125125
}
126126

127127
if (str_starts_with($name, 'test_')) {

tests/unit/Logging/TestDox/NamePrettifierTest.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,6 @@ public static function methodNameProvider(): array
8888
'',
8989
'test',
9090
],
91-
[
92-
'This is a test',
93-
'testThisIsATest',
94-
],
95-
[
96-
'This is a test',
97-
'testThisIsATest2',
98-
],
9991
[
10092
'This is a test',
10193
'this_is_a_test',
@@ -132,7 +124,8 @@ public static function methodNameProvider(): array
132124
*/
133125
public static function objectProvider(): array
134126
{
135-
$object = new class {
127+
$object = new class
128+
{
136129
public function __toString(): string
137130
{
138131
return 'object as string';
@@ -207,4 +200,12 @@ public function test_TestCase_can_be_prettified(string $expected, TestCase $test
207200
{
208201
$this->assertSame($expected, (new NamePrettifier)->prettifyTestCase($testCase, $colorize));
209202
}
203+
204+
public function testStripsNumericSuffixFromTestMethodNameWhenTestMethodNameWithoutThatSuffixWasPreviouslyProcessed(): void
205+
{
206+
$namePrettifier = new NamePrettifier;
207+
208+
$this->assertSame('This is a test', $namePrettifier->prettifyTestMethodName('testThisIsATest'));
209+
$this->assertSame('This is a test', $namePrettifier->prettifyTestMethodName('testThisIsATest2'));
210+
}
210211
}

0 commit comments

Comments
 (0)