From 3a664cab4643937b5080abcae4e58101363376ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Thu, 20 Jun 2024 10:12:12 +0200 Subject: [PATCH] optimize empty checks in TestSuite --- src/Framework/TestSuite.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Framework/TestSuite.php b/src/Framework/TestSuite.php index caad08b5080..b6b19be1e89 100644 --- a/src/Framework/TestSuite.php +++ b/src/Framework/TestSuite.php @@ -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".', @@ -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; } /** @@ -337,7 +343,7 @@ public function run(): void $this->wasRun = true; - if (count($this) === 0) { + if ($this->isEmpty()) { return; } @@ -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();