22namespace example \framework \event \test \extension ;
33
44use const DIRECTORY_SEPARATOR ;
5- use const PHP_EOL ;
65use function assert ;
76use function file_put_contents ;
87use function is_dir ;
9- use function ksort ;
108use function mkdir ;
119use function sprintf ;
1210use function str_replace ;
13- use function str_starts_with ;
1411use PHPUnit \Event \Test \AdditionalInformationProvided ;
1512use PHPUnit \Runner \Extension \Extension as ExtensionInterface ;
1613use PHPUnit \Runner \Extension \Facade as ExtensionFacade ;
@@ -24,11 +21,6 @@ final class Extension implements ExtensionInterface
2421 */
2522 private string $ targetDirectory ;
2623
27- /**
28- * @var array<string, list<array{testdox: string, specification: string}>>
29- */
30- private array $ specification = [];
31-
3224 public function bootstrap (Configuration $ configuration , ExtensionFacade $ facade , ParameterCollection $ parameters ): void
3325 {
3426 $ targetDirectory = '/tmp ' ;
@@ -43,54 +35,20 @@ public function bootstrap(Configuration $configuration, ExtensionFacade $facade,
4335
4436 $ this ->createDirectory ($ this ->targetDirectory );
4537
46- $ facade ->registerSubscribers (
47- new AdditionalInformationProvidedSubscriber ($ this ),
48- new TestRunnerExecutionFinishedSubscriber ($ this ),
49- );
38+ $ facade ->registerSubscriber (new AdditionalInformationProvidedSubscriber ($ this ));
5039 }
5140
5241 public function testProvidedAdditionalInformation (AdditionalInformationProvided $ event ): void
5342 {
54- if (str_starts_with ($ event ->additionalInformation (), 'strict digraph G { ' )) {
55- file_put_contents (
56- sprintf (
57- '%s%s%s.dot ' ,
58- $ this ->targetDirectory ,
59- DIRECTORY_SEPARATOR ,
60- str_replace (['\\' , ':: ' ], '_ ' , $ event ->test ()->id ()),
61- ),
62- $ event ->additionalInformation (),
63- );
64-
65- return ;
66- }
67-
68- if (!isset ($ this ->specification [$ event ->test ()->testDox ()->prettifiedClassName ()])) {
69- $ this ->specification [$ event ->test ()->testDox ()->prettifiedClassName ()] = [];
70- }
71-
72- $ this ->specification [$ event ->test ()->testDox ()->prettifiedClassName ()][] = [
73- 'testdox ' => $ event ->test ()->testDox ()->prettifiedMethodName (),
74- 'specification ' => $ event ->additionalInformation (),
75- ];
76- }
77-
78- public function flush (): void
79- {
80- ksort ($ this ->specification );
81-
82- $ buffer = '' ;
83-
84- foreach ($ this ->specification as $ class => $ methods ) {
85- $ buffer .= '# ' . $ class . PHP_EOL . PHP_EOL ;
86-
87- foreach ($ methods as $ method ) {
88- $ buffer .= '## ' . $ method ['testdox ' ] . PHP_EOL . PHP_EOL ;
89- $ buffer .= $ method ['specification ' ] . PHP_EOL . PHP_EOL ;
90- }
91- }
92-
93- file_put_contents ($ this ->targetDirectory . DIRECTORY_SEPARATOR . 'events.md ' , $ buffer );
43+ file_put_contents (
44+ sprintf (
45+ '%s%s%s.dot ' ,
46+ $ this ->targetDirectory ,
47+ DIRECTORY_SEPARATOR ,
48+ str_replace (['\\' , ':: ' ], '_ ' , $ event ->test ()->id ()),
49+ ),
50+ $ event ->additionalInformation (),
51+ );
9452 }
9553
9654 /**
0 commit comments