From c91a3355e10852726abb3129d609ff0699b95e61 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Sun, 15 Feb 2026 13:05:38 +0300 Subject: [PATCH] [4.x] Fixed handling of comparison of mixed parameter names --- src/Benchmark.php | 7 ++----- tests/Unit/Compares/AsArrayTest.php | 14 ++++++++++++++ tests/Unit/Compares/AsCallbackTest.php | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/Benchmark.php b/src/Benchmark.php index 7614e7c..a4a7787 100644 --- a/src/Benchmark.php +++ b/src/Benchmark.php @@ -18,7 +18,6 @@ use function abs; use function array_first; use function count; -use function func_get_args; use function is_array; use function is_callable; use function max; @@ -103,12 +102,10 @@ public function round(?int $precision): static public function compare(array|Closure ...$callbacks): static { - $values = $this->resolveCallbacks( - func_get_args() ?: $callbacks - ); - $this->clear(); + $values = $this->resolveCallbacks($callbacks); + $this->withProgress($values, $this->steps($values)); return $this; diff --git a/tests/Unit/Compares/AsArrayTest.php b/tests/Unit/Compares/AsArrayTest.php index f9d456e..1d9d01d 100644 --- a/tests/Unit/Compares/AsArrayTest.php +++ b/tests/Unit/Compares/AsArrayTest.php @@ -27,3 +27,17 @@ 1, ]); }); + +test('mixed names', function () { + $results = benchmark(false)->compare([ + static fn () => true, + 'foo' => static fn () => true, + 'bar' => static fn () => false, + ])->toData(); + + expect($results)->toHaveKeys([ + 0, + 'foo', + 'bar', + ]); +}); diff --git a/tests/Unit/Compares/AsCallbackTest.php b/tests/Unit/Compares/AsCallbackTest.php index d9d24a1..c83527f 100644 --- a/tests/Unit/Compares/AsCallbackTest.php +++ b/tests/Unit/Compares/AsCallbackTest.php @@ -27,3 +27,17 @@ 1, ]); }); + +test('mixed names', function () { + $results = benchmark(false)->compare( + static fn () => true, + foo: static fn () => true, + bar: static fn () => false, + )->toData(); + + expect($results)->toHaveKeys([ + 0, + 'foo', + 'bar', + ]); +});