|
18 | 18 | use TypePHP\Tests\Fixtures\Php85\HookedCloneWithFixture; |
19 | 19 | use TypePHP\Tests\Fixtures\Php85\MagicCloneWithFixture; |
20 | 20 | use TypePHP\Tests\Fixtures\Php85\MultiTemplateMapFixture; |
| 21 | +use TypePHP\Tests\Fixtures\Php85\NativeCloneWithRunner; |
21 | 22 | use TypePHP\Tests\Fixtures\Php85\Psr7ResponseWitherFixture; |
22 | 23 | use TypePHP\Tests\Fixtures\Php85\ShapeCloneWithFixture; |
23 | 24 | use TypePHP\TypePHP; |
|
78 | 79 | test('throws TypeError when clone override violates generic value type V', function () { |
79 | 80 | $map = new MultiTemplateMapFixture(['user_1' => 100]); |
80 | 81 |
|
81 | | - expect(fn () => clone($map, ['data' => ['user_1' => 'not_an_int']])) |
| 82 | + expect(fn () => NativeCloneWithRunner::clone($map, ['data' => ['user_1' => 'not_an_int']])) |
82 | 83 | ->toThrow(TypeError::class, "['user_1'] must be of type int") |
83 | 84 | ; |
84 | 85 | }); |
|
122 | 123 | $model = new MagicCloneWithFixture(); |
123 | 124 | expect($model->counter)->toBe(10); |
124 | 125 |
|
125 | | - // In PHP 8.5 RFC: __clone() runs (setting counter to 999), then ['counter' => 50] overwrites it |
126 | | - $cloned = clone($model, ['counter' => 50]); |
| 126 | + $cloned = NativeCloneWithRunner::clone($model, ['counter' => 50]); |
127 | 127 |
|
128 | 128 | expect($cloned->magicCloneExecuted)->toBeTrue() |
129 | 129 | ->and($cloned->counter)->toBe(50) |
|
133 | 133 | test('validates final overridden state even when __clone() mutated the object first', function () { |
134 | 134 | $model = new MagicCloneWithFixture(); |
135 | 135 |
|
136 | | - expect(fn () => clone($model, ['counter' => -100])) |
| 136 | + expect(fn () => NativeCloneWithRunner::clone($model, ['counter' => -100])) |
137 | 137 | ->toThrow(TypeError::class, 'positive-int') |
138 | 138 | ; |
139 | 139 | }); |
|
143 | 143 | test('triggers set hook during property write and enforces contract', function () { |
144 | 144 | $order = new HookedCloneWithFixture(); |
145 | 145 |
|
146 | | - $cloned = clone($order, ['total' => 250]); |
| 146 | + $cloned = NativeCloneWithRunner::clone($order, ['total' => 250]); |
147 | 147 | expect($cloned->total)->toBe(250); |
148 | 148 |
|
149 | | - expect(fn () => clone($order, ['total' => -50])) |
| 149 | + expect(fn () => NativeCloneWithRunner::clone($order, ['total' => -50])) |
150 | 150 | ->toThrow(TypeError::class, 'positive-int') |
151 | 151 | ; |
152 | 152 | }); |
|
156 | 156 | test('validates array shape properties on cloned instance', function () { |
157 | 157 | $fixture = new ShapeCloneWithFixture(); |
158 | 158 |
|
159 | | - $cloned = clone($fixture, [ |
| 159 | + $cloned = NativeCloneWithRunner::clone($fixture, [ |
160 | 160 | 'session' => ['id' => 42, 'role' => 'admin'], |
161 | 161 | ]); |
162 | 162 |
|
|
166 | 166 | test('throws TypeError when array shape id violates positive-int', function () { |
167 | 167 | $fixture = new ShapeCloneWithFixture(); |
168 | 168 |
|
169 | | - expect(fn () => clone($fixture, ['session' => ['id' => -1, 'role' => 'user']])) |
| 169 | + expect(fn () => NativeCloneWithRunner::clone($fixture, ['session' => ['id' => -1, 'role' => 'user']])) |
170 | 170 | ->toThrow(TypeError::class, "['id'] must be of type positive-int") |
171 | 171 | ; |
172 | 172 | }); |
173 | 173 |
|
174 | 174 | test('throws TypeError when array shape role violates literal union', function () { |
175 | 175 | $fixture = new ShapeCloneWithFixture(); |
176 | 176 |
|
177 | | - expect(fn () => clone($fixture, ['session' => ['id' => 10, 'role' => 'superuser']])) |
| 177 | + expect(fn () => NativeCloneWithRunner::clone($fixture, ['session' => ['id' => 10, 'role' => 'superuser']])) |
178 | 178 | ->toThrow(TypeError::class, "['role'] must be of type ('admin' | 'user')") |
179 | 179 | ; |
180 | 180 | }); |
|
206 | 206 | Config::set(['on_violation' => 'report']); |
207 | 207 |
|
208 | 208 | $user = new ShapeCloneWithFixture(); |
209 | | - $cloned = clone($user, ['session' => ['id' => -999, 'role' => 'user']]); |
| 209 | + $cloned = NativeCloneWithRunner::clone($user, ['session' => ['id' => -999, 'role' => 'user']]); |
210 | 210 |
|
211 | 211 | expect($cloned)->toBeInstanceOf(ShapeCloneWithFixture::class); |
212 | 212 |
|
|
0 commit comments