Skip to content

Commit d6df72d

Browse files
[4.x] Replace prepare method with beforeEach
Closes #36
1 parent bd6ebe4 commit d6df72d

3 files changed

Lines changed: 11 additions & 10 deletions

File tree

UPGRADING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
## From 3 to 4
44

55
- Удалён метод `withoutData`
6+
- Метод `prepare` переименован в `beforeEach`

src/Benchmark.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Benchmark
2727

2828
protected int $iterations = 100;
2929

30-
protected ?Closure $prepare = null;
30+
protected ?Closure $beforeEach = null;
3131

3232
protected array $result = [
3333
'each' => [],
@@ -51,9 +51,9 @@ public static function start(): static
5151
return new static();
5252
}
5353

54-
public function prepare(callable $callback): self
54+
public function beforeEach(callable $callback): self
5555
{
56-
$this->prepare = $callback;
56+
$this->beforeEach = $callback;
5757

5858
return $this;
5959
}
@@ -114,7 +114,7 @@ protected function each(mixed $name, callable $callback, ProgressBarService $pro
114114
protected function run(mixed $name, callable $callback, ProgressBarService $progressBar): void
115115
{
116116
for ($i = 1; $i <= $this->iterations; ++$i) {
117-
$result = $this->runPrepare($name, $i);
117+
$result = $this->runBeforeEach($name, $i);
118118

119119
[$time, $ram] = $this->call($callback, [$i, $result]);
120120

@@ -124,9 +124,9 @@ protected function run(mixed $name, callable $callback, ProgressBarService $prog
124124
}
125125
}
126126

127-
protected function runPrepare(mixed $name, int $iteration): mixed
127+
protected function runBeforeEach(mixed $name, int $iteration): mixed
128128
{
129-
if ($callback = $this->prepare) {
129+
if ($callback = $this->beforeEach) {
130130
return $callback($name, $iteration);
131131
}
132132

tests/Benchmark/PrepareTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function testCallback(): void
1414

1515
$this->benchmark()
1616
->iterations(3)
17-
->prepare(function () use (&$result) {
17+
->beforeEach(function () use (&$result) {
1818
$result[] = 1;
1919
})
2020
->compare([
@@ -31,7 +31,7 @@ public function testParameters(): void
3131

3232
$this->benchmark()
3333
->iterations(3)
34-
->prepare(function (mixed $name, int $iteration) use (&$result) {
34+
->beforeEach(function (mixed $name, int $iteration) use (&$result) {
3535
$result[] = sprintf('%s:%d', $name, $iteration);
3636
})
3737
->compare([
@@ -57,7 +57,7 @@ public function testName(): void
5757

5858
$this->benchmark()
5959
->iterations(3)
60-
->prepare(function (mixed $name) use (&$result) {
60+
->beforeEach(function (mixed $name) use (&$result) {
6161
$result[] = $name;
6262
})
6363
->compare([
@@ -81,7 +81,7 @@ public function testPrepareResult(): void
8181
{
8282
$this->benchmark()
8383
->iterations(3)
84-
->prepare(
84+
->beforeEach(
8585
fn (mixed $name, int $iteration) => sprintf('%s:%d', $name, $iteration)
8686
)
8787
->compare([

0 commit comments

Comments
 (0)