Skip to content

Commit 5576e6a

Browse files
Merge pull request #71
[4.x] Fix coverage
2 parents e96c438 + e6b42c5 commit 5576e6a

3 files changed

Lines changed: 33 additions & 26 deletions

File tree

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
}
3838
],
3939
"require": {
40-
"php": "^8.2"
40+
"php": "^8.2",
41+
"symfony/polyfill-php85": "^1.33"
4142
},
4243
"require-dev": {
4344
"pestphp/pest": "^3.8 || ^4.0",

src/Benchmark.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use DragonCode\Benchmark\View\ProgressBarView;
1717

1818
use function abs;
19+
use function array_first;
1920
use function count;
2021
use function func_get_args;
2122
use function is_array;
@@ -84,11 +85,9 @@ public function round(?int $precision): self
8485

8586
public function compare(array|Closure ...$callbacks): static
8687
{
87-
$values = match (true) {
88-
is_array($callbacks[0] ?? null) => $callbacks[0],
89-
is_array($callbacks) => $callbacks,
90-
default => func_get_args()
91-
};
88+
$values = $this->resolveCallbacks(
89+
func_get_args() ?: $callbacks
90+
);
9291

9392
$this->clear();
9493

@@ -180,6 +179,13 @@ protected function push(mixed $name, float $time, float $memory): void
180179
$this->collector->push($name, [$time, $memory]);
181180
}
182181

182+
protected function resolveCallbacks(array $callbacks): array
183+
{
184+
$first = array_first($callbacks);
185+
186+
return is_array($first) ? $first : $callbacks;
187+
}
188+
183189
protected function validate(mixed $callback): void
184190
{
185191
if (! is_callable($callback)) {

tests/Unit/Assertions/ToBeTotalTimeTest.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,30 @@
22

33
declare(strict_types=1);
44

5-
//test('success', function () {
6-
// benchmark()
7-
// ->assert()
8-
// ->toBeTotalTime(1, 1000);
9-
//
10-
// expect(true)->toBeTrue();
11-
//});
12-
//
13-
//test('success without arguments', function () {
14-
// benchmark()
15-
// ->assert()
16-
// ->toBeTotalTime();
17-
//
18-
// expect(true)->toBeTrue();
19-
//});
5+
test('success', function () {
6+
benchmark()
7+
->assert()
8+
->toBeTotalTime(1, 1000);
9+
10+
expect(true)->toBeTrue();
11+
});
12+
13+
test('success without arguments', function () {
14+
benchmark()
15+
->assert()
16+
->toBeTotalTime();
17+
18+
expect(true)->toBeTrue();
19+
});
2020

2121
test('failure greater than', function () {
2222
benchmark()
2323
->assert()
2424
->toBeTotalTime(from: 1000);
2525
})->throws(AssertionError::class, 'The total time value must be greater than or equal to 1000.');
2626

27-
//test('failure less than', function () {
28-
// benchmark()
29-
// ->assert()
30-
// ->toBeTotalTime(till: 10);
31-
//})->throws(AssertionError::class, 'The total time value must be less than or equal to 10.');
27+
test('failure less than', function () {
28+
benchmark()
29+
->assert()
30+
->toBeTotalTime(till: 10);
31+
})->throws(AssertionError::class, 'The total time value must be less than or equal to 10.');

0 commit comments

Comments
 (0)