Skip to content

Commit

Permalink
optimize empty checks in TestSuite
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek authored and sebastianbergmann committed Jun 20, 2024
1 parent 933af56 commit 3a664ca
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Framework/TestSuite.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public static function fromClassReflector(ReflectionClass $class): static
$testSuite->addTestMethod($class, $method);
}

if (count($testSuite) === 0) {
if ($testSuite->isEmpty()) {
Event\Facade::emitter()->testRunnerTriggeredWarning(
sprintf(
'No tests found in class "%s".',
Expand Down Expand Up @@ -290,7 +290,13 @@ public function count(): int

public function isEmpty(): bool
{
return empty($this->tests);
foreach ($this as $test) {
if (count($test) !== 0) {
return false;
}
}

return true;
}

/**
Expand Down Expand Up @@ -337,7 +343,7 @@ public function run(): void

$this->wasRun = true;

if (count($this) === 0) {
if ($this->isEmpty()) {
return;
}

Expand All @@ -362,7 +368,7 @@ public function run(): void
$this->tests = [];
$this->groups = [];

while (($test = array_pop($tests)) !== false) {
while (($test = array_pop($tests)) !== null) {
if (TestResultFacade::shouldStop()) {
$emitter->testRunnerExecutionAborted();

Expand Down

0 comments on commit 3a664ca

Please sign in to comment.