Skip to content

Commit c71a69a

Browse files
committed
fix: show when no test found
1 parent 521078a commit c71a69a

File tree

3 files changed

+28
-27
lines changed

3 files changed

+28
-27
lines changed

src/Console/Controllers/RunTestController.php

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ protected function runJUnit(RunTestService $service): ResponseInterface
6060
$suitesXml = $suites->outputMemory();
6161

6262
// Duration: pick your source (internal timer is fine)
63-
$inst = TestDiscovery::getUnitaryInst();
63+
$inst = TestDiscovery::getUnitaryInst(true);
6464
$xml = new \XMLWriter();
6565
$xml->openMemory();
6666
$xml->setIndent(true);
@@ -91,29 +91,27 @@ protected function runJUnit(RunTestService $service): ResponseInterface
9191
*/
9292
protected function buildFooter(): void
9393
{
94-
$inst = TestDiscovery::getUnitaryInst();
95-
if ($inst !== null) {
96-
$dot = $this->command->getAnsi()->middot();
97-
$this->command->message($this->command->getAnsi()->line(80));
98-
$this->command->message(
99-
$this->command->getAnsi()->style(
100-
["bold", $inst::isSuccessful() ? "green" : "red"],
101-
"\nTests: " . $inst::getTotalTests() . " $dot " .
102-
"Failures: " . $inst::getTotalFailed() . " $dot " .
103-
"Errors: " . $inst::getTotalErrors() . " $dot " .
104-
"Skipped: " . $inst::getTotalSkipped() . " \n"
105-
)
106-
);
107-
$this->command->message(
108-
$this->command->getAnsi()->style(
109-
["italic", "grey"],
110-
"Duration: " . Helpers::formatDuration($inst::getTotalDuration()) . " seconds $dot " .
111-
"Memory: " . Helpers::byteToMegabyte($inst::getTotalMemory()) . " MB $dot " .
112-
"Date: " . Clock::value("now")->iso() . "\n"
113-
)
114-
);
115-
$this->command->message($this->command->getAnsi()->line(80));
116-
$this->command->message("");
117-
}
94+
$inst = TestDiscovery::getUnitaryInst(true);
95+
$dot = $this->command->getAnsi()->middot();
96+
$this->command->message($this->command->getAnsi()->line(80));
97+
$this->command->message(
98+
$this->command->getAnsi()->style(
99+
["bold", $inst::isSuccessful() ? "green" : "red"],
100+
"\nTests: " . $inst::getTotalTests() . " $dot " .
101+
"Failures: " . $inst::getTotalFailed() . " $dot " .
102+
"Errors: " . $inst::getTotalErrors() . " $dot " .
103+
"Skipped: " . $inst::getTotalSkipped() . " \n"
104+
)
105+
);
106+
$this->command->message(
107+
$this->command->getAnsi()->style(
108+
["italic", "grey"],
109+
"Duration: " . Helpers::formatDuration($inst::getTotalDuration()) . " seconds $dot " .
110+
"Memory: " . Helpers::byteToMegabyte($inst::getTotalMemory()) . " MB $dot " .
111+
"Date: " . Clock::value("now")->iso() . "\n"
112+
)
113+
);
114+
$this->command->message($this->command->getAnsi()->line(80));
115+
$this->command->message("");
118116
}
119117
}

src/Discovery/TestDiscovery.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,14 @@ protected function runBlunder(): void
362362
* This is primary used to access the main test Unit instance that is
363363
* pre-initialized for each test file. Is used by shortcut function like `group()`
364364
*
365+
* @param bool $initIfNull
365366
* @return Unit|null
366367
*/
367-
public static function getUnitaryInst(): ?Unit
368+
public static function getUnitaryInst(bool $initIfNull = false): ?Unit
368369
{
370+
if ($initIfNull) {
371+
self::$unitary = new Unit();
372+
}
369373
return self::$unitary;
370374
}
371375
}

src/Renders/CliRenderer.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ public function __construct(Command $command)
3434
public function buildBody(): void
3535
{
3636
$this->initDefault();
37-
3837
$this->command->message("");
3938
$this->command->message(
4039
$this->flag . " " .

0 commit comments

Comments
 (0)