@@ -59,6 +59,11 @@ final class NamePrettifier
59
59
*/
60
60
private array $ strings = [];
61
61
62
+ /**
63
+ * @var array<non-empty-string, non-empty-string>
64
+ */
65
+ private array $ prettifiedTestCases = [];
66
+
62
67
/**
63
68
* @param class-string $className
64
69
*/
@@ -172,40 +177,39 @@ public function prettifyTestMethodName(string $name): string
172
177
173
178
public function prettifyTestCase (TestCase $ test , bool $ colorize ): string
174
179
{
175
- $ annotationWithPlaceholders = false ;
176
- $ methodLevelTestDox = MetadataRegistry::parser ()->forMethod ($ test ::class, $ test ->name ())->isTestDox ()->isMethodLevel ();
180
+ $ key = $ test ::class . '# ' . $ test ->name ();
177
181
178
- if ($ methodLevelTestDox ->isNotEmpty ()) {
179
- $ methodLevelTestDox = $ methodLevelTestDox ->asArray ()[0 ];
182
+ if ($ test ->usesDataProvider ()) {
183
+ $ key .= '# ' . $ test ->dataName ();
184
+ }
180
185
181
- assert ($ methodLevelTestDox instanceof TestDox);
186
+ if ($ colorize ) {
187
+ $ key .= '#colorize ' ;
188
+ }
182
189
183
- $ result = $ methodLevelTestDox ->text ();
190
+ if (isset ($ this ->prettifiedTestCases [$ key ])) {
191
+ return $ this ->prettifiedTestCases [$ key ];
192
+ }
184
193
185
- if (str_contains ($ result , '$ ' )) {
186
- $ annotation = $ result ;
187
- $ providedData = $ this ->mapTestMethodParameterNamesToProvidedDataValues ($ test , $ colorize );
194
+ $ testDox = MetadataRegistry::parser ()->forMethod ($ test ::class, $ test ->name ())->isTestDox ()->isMethodLevel ();
195
+ $ isCustomized = false ;
188
196
189
- $ variables = array_map (
190
- static fn (string $ variable ): string => sprintf (
191
- '/%s(?=\b)/ ' ,
192
- preg_quote ($ variable , '/ ' ),
193
- ),
194
- array_keys ($ providedData ),
195
- );
197
+ if ($ testDox ->isNotEmpty ()) {
198
+ $ testDox = $ testDox ->asArray ()[0 ];
196
199
197
- $ result = preg_replace ( $ variables , $ providedData , $ annotation );
200
+ assert ( $ testDox instanceof TestDox );
198
201
199
- $ annotationWithPlaceholders = true ;
200
- }
202
+ [$ result , $ isCustomized ] = $ this ->processTestDox ($ test , $ testDox , $ colorize );
201
203
} else {
202
204
$ result = $ this ->prettifyTestMethodName ($ test ->name ());
203
205
}
204
206
205
- if (!$ annotationWithPlaceholders && $ test ->usesDataProvider ()) {
207
+ if (!$ isCustomized && $ test ->usesDataProvider ()) {
206
208
$ result .= $ this ->prettifyDataSet ($ test , $ colorize );
207
209
}
208
210
211
+ $ this ->prettifiedTestCases [$ key ] = $ result ;
212
+
209
213
return $ result ;
210
214
}
211
215
@@ -305,4 +309,33 @@ private function objectToString(object $value): string
305
309
306
310
return $ value ::class;
307
311
}
312
+
313
+ /**
314
+ * @return array{0: string, 1: bool}
315
+ */
316
+ private function processTestDox (TestCase $ test , TestDox $ testDox , bool $ colorize ): array
317
+ {
318
+ $ placeholdersUsed = false ;
319
+
320
+ $ result = $ testDox ->text ();
321
+
322
+ if (str_contains ($ result , '$ ' )) {
323
+ $ annotation = $ result ;
324
+ $ providedData = $ this ->mapTestMethodParameterNamesToProvidedDataValues ($ test , $ colorize );
325
+
326
+ $ variables = array_map (
327
+ static fn (string $ variable ): string => sprintf (
328
+ '/%s(?=\b)/ ' ,
329
+ preg_quote ($ variable , '/ ' ),
330
+ ),
331
+ array_keys ($ providedData ),
332
+ );
333
+
334
+ $ result = preg_replace ($ variables , $ providedData , $ annotation );
335
+
336
+ $ placeholdersUsed = true ;
337
+ }
338
+
339
+ return [$ result , $ placeholdersUsed ];
340
+ }
308
341
}
0 commit comments