Skip to content

Commit a8cccf7

Browse files
[4.x] Update UPGRADING.md with detailed migration instructions
1 parent e20961d commit a8cccf7

File tree

1 file changed

+144
-8
lines changed

1 file changed

+144
-8
lines changed

UPGRADING.md

Lines changed: 144 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,147 @@
22

33
## From 3 to 4
44

5-
- Удалён метод `withoutData`
6-
- Метод `prepare` переименован в `beforeEach`
7-
- Метод `start` переименован в `make`
8-
- Исправлена типизация входящих колбэков с супер-класса `callable` на `Closure`
9-
- Класс `ValueIsNotCallableException` теперь принимает объект вместо строки типа.
10-
- Все имена классов теперь имеют обязательные суффиксы.
11-
- Удалён контракт `Transformer`
12-
- Remove unused `ArrayService` class
5+
### High Impact Changes
6+
7+
#### The `start` Method Renamed To `make`
8+
9+
The static factory method `start` has been renamed to `make`:
10+
11+
```php
12+
// Before
13+
Benchmark::start()
14+
15+
// After
16+
Benchmark::make()
17+
```
18+
19+
#### The `prepare` Method Renamed To `beforeEach`
20+
21+
The `prepare` method has been renamed to `beforeEach`:
22+
23+
```php
24+
// Before
25+
Benchmark::start()
26+
->prepare(function (string $name, int $iteration) {
27+
// ...
28+
})
29+
30+
// After
31+
Benchmark::make()
32+
->beforeEach(function (string $name, int $iteration) {
33+
// ...
34+
})
35+
```
36+
37+
#### The `compare` Method No Longer Outputs Results Directly
38+
39+
The `compare` method now returns `static` instead of `void`. To get results, you must explicitly call one of the output methods:
40+
41+
- `toConsole()` — prints the result table to the console
42+
- `toData()` — returns an array of `ResultData` objects
43+
- `toAssert()` — returns an `AssertService` instance for assertions
44+
45+
```php
46+
// Before
47+
Benchmark::start()
48+
->compare(
49+
fn () => /* ... */,
50+
fn () => /* ... */,
51+
);
52+
53+
// After
54+
Benchmark::make()
55+
->compare(
56+
fn () => /* ... */,
57+
fn () => /* ... */,
58+
)
59+
->toConsole();
60+
```
61+
62+
#### The `withoutData` Method Has Been Removed
63+
64+
The `withoutData` method has been removed without replacement.
65+
66+
#### Fluent Methods Now Return `static` Instead Of `self`
67+
68+
All fluent methods (`iterations`, `round`, `beforeEach`, `afterEach`, `before`, `after`, `compare`, `toConsole`) now return `static` instead of `self` for better extensibility.
69+
70+
### Medium Impact Changes
71+
72+
#### The `Transformer` Contract Has Been Removed
73+
74+
The `DragonCode\Benchmark\Contracts\Transformer` interface has been removed. If you implemented this interface, use the new `ResultTransformer` class instead.
75+
76+
#### The `ValueIsNotCallableException` Constructor Changed
77+
78+
The exception now accepts a `mixed` value (the actual object) instead of a `string` type name:
79+
80+
```php
81+
// Before
82+
throw new ValueIsNotCallableException(gettype($value));
83+
84+
// After
85+
throw new ValueIsNotCallableException($value);
86+
```
87+
88+
#### Dependencies Changed
89+
90+
- Removed `dragon-code/support` dependency
91+
- Removed `symfony/console` dependency
92+
- Added `symfony/polyfill-php85` dependency
93+
94+
If your project relied on `dragon-code/support` or `symfony/console` being pulled in transitively, you must now require them directly.
95+
96+
### Low Impact Changes
97+
98+
#### Renamed Service Classes
99+
100+
All service classes now have a `Service` suffix:
101+
102+
| Before (3.x) | After (4.x) |
103+
|-----------------------------|------------------------------------|
104+
| `Services\Arr` | Removed |
105+
| `Services\MeasurementError` | `Services\MeasurementErrorService` |
106+
| `Services\Memory` | `Services\MemoryService` |
107+
| `Services\Runner` | `Services\RunnerService` |
108+
| `Services\View` | `Services\ViewService` |
109+
110+
#### Renamed View Classes
111+
112+
All view classes now have a `View` suffix:
113+
114+
| Before (3.x) | After (4.x) |
115+
|--------------------|------------------------|
116+
| `View\ProgressBar` | `View\ProgressBarView` |
117+
| `View\Table` | `View\TableView` |
118+
119+
#### Renamed Transformer Classes
120+
121+
The old transformer classes (`Base`, `Separator`, `Stats`, `Times`, `Transformer`, `Winner`) have been removed and replaced with a single `ResultTransformer` class.
122+
123+
#### The `ArrayService` Class Has Been Removed
124+
125+
The `DragonCode\Benchmark\Services\Arr` class has been removed without replacement.
126+
127+
#### New `Data` Classes
128+
129+
New DTO classes have been introduced:
130+
131+
- `DragonCode\Benchmark\Data\ResultData`
132+
- `DragonCode\Benchmark\Data\MetricData`
133+
134+
#### New Callback Methods
135+
136+
New lifecycle callback methods have been added:
137+
138+
- `before(Closure $callback)` — called once before each named callback group
139+
- `after(Closure $callback)` — called once after each named callback group
140+
- `afterEach(Closure $callback)` — called after each iteration
141+
142+
#### The `ram` Terminology Replaced With `memory`
143+
144+
All internal references to `ram` have been renamed to `memory` for consistency.
145+
146+
#### The `assert` Method Renamed to `toAssert`
147+
148+
The `assert` method has been renamed to `toAssert` and now returns an `AssertService` instance instead of `static`.

0 commit comments

Comments
 (0)