Skip to content

Commit 44bc99f

Browse files
Merge pull request #90
[4.x] Fixed handling of comparison of mixed parameter names
2 parents 07c2358 + c91a335 commit 44bc99f

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

src/Benchmark.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use function abs;
1919
use function array_first;
2020
use function count;
21-
use function func_get_args;
2221
use function is_array;
2322
use function is_callable;
2423
use function max;
@@ -103,12 +102,10 @@ public function round(?int $precision): static
103102

104103
public function compare(array|Closure ...$callbacks): static
105104
{
106-
$values = $this->resolveCallbacks(
107-
func_get_args() ?: $callbacks
108-
);
109-
110105
$this->clear();
111106

107+
$values = $this->resolveCallbacks($callbacks);
108+
112109
$this->withProgress($values, $this->steps($values));
113110

114111
return $this;

tests/Unit/Compares/AsArrayTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,17 @@
2727
1,
2828
]);
2929
});
30+
31+
test('mixed names', function () {
32+
$results = benchmark(false)->compare([
33+
static fn () => true,
34+
'foo' => static fn () => true,
35+
'bar' => static fn () => false,
36+
])->toData();
37+
38+
expect($results)->toHaveKeys([
39+
0,
40+
'foo',
41+
'bar',
42+
]);
43+
});

tests/Unit/Compares/AsCallbackTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,17 @@
2727
1,
2828
]);
2929
});
30+
31+
test('mixed names', function () {
32+
$results = benchmark(false)->compare(
33+
static fn () => true,
34+
foo: static fn () => true,
35+
bar: static fn () => false,
36+
)->toData();
37+
38+
expect($results)->toHaveKeys([
39+
0,
40+
'foo',
41+
'bar',
42+
]);
43+
});

0 commit comments

Comments
 (0)