2323use function fwrite ;
2424use function getcwd ;
2525use function getenv ;
26- use function round ;
27- use function str_repeat ;
2826use function str_starts_with ;
2927
3028final class OpenApiCoverageExtension implements Extension
@@ -59,15 +57,20 @@ public function bootstrap(Configuration $configuration, Facade $facade, Paramete
5957 }
6058 }
6159
60+ $ consoleOutput = ConsoleOutput::resolve (
61+ $ parameters ->has ('console_output ' ) ? $ parameters ->get ('console_output ' ) : null ,
62+ );
63+
6264 $ githubSummaryPath = getenv ('GITHUB_STEP_SUMMARY ' ) ?: null ;
6365
64- $ facade ->registerSubscriber (new class ($ specs , $ outputFile , $ githubSummaryPath ) implements ExecutionFinishedSubscriber {
66+ $ facade ->registerSubscriber (new class ($ specs , $ outputFile , $ consoleOutput , $ githubSummaryPath ) implements ExecutionFinishedSubscriber {
6567 /**
6668 * @param string[] $specs
6769 */
6870 public function __construct (
6971 private readonly array $ specs ,
7072 private readonly ?string $ outputFile ,
73+ private readonly ConsoleOutput $ consoleOutput ,
7174 private readonly ?string $ githubSummaryPath ,
7275 ) {}
7376
@@ -80,7 +83,7 @@ public function notify(ExecutionFinished $event): void
8083 return ;
8184 }
8285
83- $ this ->printReport ( $ results );
86+ echo ConsoleCoverageRenderer:: render ( $ results , $ this ->consoleOutput );
8487
8588 if ($ this ->outputFile !== null || $ this ->githubSummaryPath !== null ) {
8689 $ this ->writeMarkdownReport ($ results );
@@ -122,39 +125,6 @@ private function computeAllResults(): array
122125 return $ results ;
123126 }
124127
125- /**
126- * @param array<string, array{covered: string[], uncovered: string[], total: int, coveredCount: int}> $results
127- */
128- private function printReport (array $ results ): void
129- {
130- echo "\n\n" ;
131- echo "OpenAPI Contract Test Coverage \n" ;
132- echo str_repeat ('= ' , 50 ) . "\n" ;
133-
134- foreach ($ results as $ spec => $ result ) {
135- $ percentage = self ::percentage ($ result ['coveredCount ' ], $ result ['total ' ]);
136-
137- echo "\n[ {$ spec }] {$ result ['coveredCount ' ]}/ {$ result ['total ' ]} endpoints ( {$ percentage }%) \n" ;
138- echo str_repeat ('- ' , 50 ) . "\n" ;
139-
140- if ($ result ['covered ' ] !== []) {
141- echo "Covered: \n" ;
142-
143- foreach ($ result ['covered ' ] as $ endpoint ) {
144- echo " ✓ {$ endpoint }\n" ;
145- }
146- }
147-
148- $ uncoveredCount = $ result ['total ' ] - $ result ['coveredCount ' ];
149-
150- if ($ uncoveredCount > 0 ) {
151- echo "Uncovered: {$ uncoveredCount } endpoints \n" ;
152- }
153- }
154-
155- echo "\n" ;
156- }
157-
158128 /**
159129 * @param array<string, array{covered: string[], uncovered: string[], total: int, coveredCount: int}> $results
160130 */
@@ -178,11 +148,6 @@ private function writeMarkdownReport(array $results): void
178148 }
179149 }
180150 }
181-
182- private static function percentage (int $ covered , int $ total ): float |int
183- {
184- return $ total > 0 ? round ($ covered / $ total * 100 , 1 ) : 0 ;
185- }
186151 });
187152 }
188153}
0 commit comments