@@ -66,9 +66,7 @@ final class MetricsCommandTest extends TestCase
6666 */
6767 private ObjectProphecy $ process ;
6868
69- private string $ jsonReport ;
70-
71- private string $ summaryReport ;
69+ private string $ target ;
7270
7371 private MetricsCommand $ command ;
7472
@@ -82,12 +80,9 @@ protected function setUp(): void
8280 $ this ->input = $ this ->prophesize (InputInterface::class);
8381 $ this ->output = $ this ->prophesize (OutputInterface::class);
8482 $ this ->process = $ this ->prophesize (Process::class);
85- $ this ->jsonReport = sys_get_temp_dir () . '/metrics- ' . uniqid () . '.json ' ;
86- $ this ->summaryReport = sys_get_temp_dir () . '/metrics-summary- ' . uniqid () . '.json ' ;
87- $ jsonReport = $ this ->jsonReport ;
88- $ summaryReport = $ this ->summaryReport ;
83+ $ this ->target = sys_get_temp_dir () . '/metrics- ' . uniqid ();
8984
90- foreach (['exclude ' , 'report-html ' , ' report-json ' , ' report-summary-json ' , 'junit ' ] as $ option ) {
85+ foreach (['exclude ' , 'target ' , 'junit ' ] as $ option ) {
9186 $ this ->input ->getOption ($ option )
9287 ->willReturn ($ this ->commandDefaultOption ($ option ));
9388 }
@@ -98,16 +93,7 @@ protected function setUp(): void
9893 ->willReturn ($ this ->process ->reveal ());
9994
10095 $ this ->processQueue ->run ($ this ->output ->reveal ())
101- ->will (static function () use ($ summaryReport , $ jsonReport ): int {
102- file_put_contents ($ summaryReport , <<<'JSON'
103- {"OOP":{"classes":2},"Complexity":{"avgCyclomaticComplexityByClass":4}}
104- JSON);
105- file_put_contents ($ jsonReport , <<<'JSON'
106- {"App\\Foo":{"_type":"Hal\\Metric\\ClassMetric","mi":80,"methods":[{"_type":"Hal\\Metric\\FunctionMetric"},{"_type":"Hal\\Metric\\FunctionMetric"}]},"App\\Bar":{"_type":"Hal\\Metric\\ClassMetric","mi":70}}
107- JSON);
108-
109- return MetricsCommand::SUCCESS ;
110- });
96+ ->willReturn (MetricsCommand::SUCCESS );
11197
11298 $ this ->command = new MetricsCommand ($ this ->processBuilder ->reveal (), $ this ->processQueue ->reveal ());
11399 }
@@ -117,7 +103,7 @@ protected function setUp(): void
117103 */
118104 protected function tearDown (): void
119105 {
120- foreach ([$ this ->jsonReport , $ this ->summaryReport ] as $ path ) {
106+ foreach ([$ this ->target . ' /report.json ' , $ this ->target . ' /report-summary.json ' ] as $ path ) {
121107 if (file_exists ($ path )) {
122108 \unlink ($ path );
123109 }
@@ -149,9 +135,10 @@ public function commandWillHaveExpectedOptions(): void
149135 self ::assertFalse ($ definition ->hasOption ('working-dir ' ));
150136 self ::assertFalse ($ definition ->hasOption ('src ' ));
151137 self ::assertTrue ($ definition ->hasOption ('exclude ' ));
152- self ::assertTrue ($ definition ->hasOption ('report-html ' ));
153- self ::assertTrue ($ definition ->hasOption ('report-json ' ));
154- self ::assertTrue ($ definition ->hasOption ('report-summary-json ' ));
138+ self ::assertTrue ($ definition ->hasOption ('target ' ));
139+ self ::assertFalse ($ definition ->hasOption ('report-html ' ));
140+ self ::assertFalse ($ definition ->hasOption ('report-json ' ));
141+ self ::assertFalse ($ definition ->hasOption ('report-summary-json ' ));
155142 self ::assertTrue ($ definition ->hasOption ('junit ' ));
156143 self ::assertFalse ($ definition ->hasOption ('cache-dir ' ));
157144 }
@@ -176,10 +163,15 @@ public function executeWillRunPhpMetrics(): void
176163 )
177164 ->shouldBeCalledOnce ()
178165 ->willReturn ($ this ->processBuilder ->reveal ());
179- $ this ->processBuilder ->withArgument ('--report-json ' , $ this ->jsonReport )
166+ $ this ->processBuilder ->withArgument ('--target ' , null )
167+ ->shouldNotBeCalled ();
168+ $ this ->processBuilder ->withArgument ('--report-html ' , $ this ->target )
169+ ->shouldBeCalledOnce ()
170+ ->willReturn ($ this ->processBuilder ->reveal ());
171+ $ this ->processBuilder ->withArgument ('--report-json ' , $ this ->target . '/report.json ' )
180172 ->shouldBeCalledOnce ()
181173 ->willReturn ($ this ->processBuilder ->reveal ());
182- $ this ->processBuilder ->withArgument ('--report-summary-json ' , $ this ->summaryReport )
174+ $ this ->processBuilder ->withArgument ('--report-summary-json ' , $ this ->target . ' /report-summary.json ' )
183175 ->shouldBeCalledOnce ()
184176 ->willReturn ($ this ->processBuilder ->reveal ());
185177 $ this ->processBuilder ->withArgument ('--junit ' , null )
@@ -199,17 +191,18 @@ public function executeWillRunPhpMetrics(): void
199191 #[Test]
200192 public function executeWillSkipUnsetOptionalReports (): void
201193 {
202- $ this ->input ->getOption ('report-json ' )
203- ->willReturn (null );
204- $ this ->input ->getOption ('report-summary-json ' )
205- ->willReturn (null );
194+ $ this ->input ->getOption ('target ' )
195+ ->willReturn ('build/metrics/ ' );
206196 $ this ->input ->getOption ('junit ' )
207197 ->willReturn (null );
208198
209- $ this ->processBuilder ->withArgument ('--report-json ' , null )
199+ $ this ->processBuilder ->withArgument ('--report-html ' , 'build/metrics ' )
200+ ->shouldBeCalledOnce ()
201+ ->willReturn ($ this ->processBuilder ->reveal ());
202+ $ this ->processBuilder ->withArgument ('--report-json ' , 'build/metrics/report.json ' )
210203 ->shouldBeCalledOnce ()
211204 ->willReturn ($ this ->processBuilder ->reveal ());
212- $ this ->processBuilder ->withArgument ('--report-summary-json ' , null )
205+ $ this ->processBuilder ->withArgument ('--report-summary-json ' , ' build/metrics/report-summary.json ' )
213206 ->shouldBeCalledOnce ()
214207 ->willReturn ($ this ->processBuilder ->reveal ());
215208 $ this ->processBuilder ->withArgument ('--junit ' , Argument::any ())
@@ -224,14 +217,12 @@ public function executeWillSkipUnsetOptionalReports(): void
224217 * @return void
225218 */
226219 #[Test]
227- public function executeWillIncludeHtmlReportWhenRequested (): void
220+ public function executeWillIncludeJunitReportWhenRequested (): void
228221 {
229- $ this ->input ->getOption ('report-html ' )
230- ->willReturn ('build/metrics ' );
231222 $ this ->input ->getOption ('junit ' )
232- ->willReturn (null );
223+ ->willReturn (' build/metrics/junit.xml ' );
233224
234- $ this ->processBuilder ->withArgument ('--report-html ' , 'build/metrics ' )
225+ $ this ->processBuilder ->withArgument ('--junit ' , 'build/metrics/junit.xml ' )
235226 ->shouldBeCalledOnce ()
236227 ->willReturn ($ this ->processBuilder ->reveal ());
237228 $ this ->processQueue ->add ($ this ->process ->reveal ())
@@ -249,8 +240,7 @@ private function commandDefaultOption(string $option): mixed
249240 {
250241 return match ($ option ) {
251242 'exclude ' => 'vendor,test,tests,tmp,cache,spec,build,backup,resources ' ,
252- 'report-json ' => $ this ->jsonReport ,
253- 'report-summary-json ' => $ this ->summaryReport ,
243+ 'target ' => $ this ->target ,
254244 'junit ' => null ,
255245 default => null ,
256246 };
0 commit comments