From 933af567cd3f9e1cfdcbcdf13f999938a64c0dbf 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:07:46 +0200 Subject: [PATCH 1/3] Use array_pop instead of slow array_shift --- src/Framework/TestSuite.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Framework/TestSuite.php b/src/Framework/TestSuite.php index 6f9fc6e330..caad08b508 100644 --- a/src/Framework/TestSuite.php +++ b/src/Framework/TestSuite.php @@ -12,7 +12,8 @@ use const PHP_EOL; use function array_keys; use function array_map; -use function array_shift; +use function array_pop; +use function array_reverse; use function assert; use function call_user_func; use function class_exists; @@ -356,10 +357,12 @@ public function run(): void $tests[] = $test; } + $tests = array_reverse($tests); + $this->tests = []; $this->groups = []; - while ($test = array_shift($tests)) { + while (($test = array_pop($tests)) !== false) { if (TestResultFacade::shouldStop()) { $emitter->testRunnerExecutionAborted(); 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 2/3] 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 caad08b508..b6b19be1e8 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(); From 46e02a39ec06775bee6fe53f9220168facc26fd3 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Thu, 20 Jun 2024 10:44:37 +0200 Subject: [PATCH 3/3] Update ChangeLog --- ChangeLog-10.5.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ChangeLog-10.5.md b/ChangeLog-10.5.md index 222a176c8a..cd8252bed2 100644 --- a/ChangeLog-10.5.md +++ b/ChangeLog-10.5.md @@ -2,6 +2,12 @@ All notable changes of the PHPUnit 10.5 release series are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles. +## [10.5.24] - 2024-MM-DD + +### Changed + +* [#5877](https://github.com/sebastianbergmann/phpunit/pull/5877): Use `array_pop()` instead of `array_shift()` for processing `Test` objects in `TestSuite::run()` and optimize `TestSuite::isEmpty()` + ## [10.5.23] - 2024-06-20 ### Changed @@ -222,6 +228,7 @@ All notable changes of the PHPUnit 10.5 release series are documented in this fi * [#5563](https://github.com/sebastianbergmann/phpunit/issues/5563): `createMockForIntersectionOfInterfaces()` does not automatically register mock object for expectation verification +[10.5.24]: https://github.com/sebastianbergmann/phpunit/compare/10.5.23...10.5 [10.5.23]: https://github.com/sebastianbergmann/phpunit/compare/10.5.22...10.5.23 [10.5.22]: https://github.com/sebastianbergmann/phpunit/compare/10.5.21...10.5.22 [10.5.21]: https://github.com/sebastianbergmann/phpunit/compare/10.5.20...10.5.21