|
19 | 19 | use CodeIgniter\Entity\Entity; |
20 | 20 | use CodeIgniter\Exceptions\InvalidArgumentException; |
21 | 21 | use Config\Database; |
22 | | -use DateTimeInterface; |
23 | 22 | use PHPUnit\Framework\Attributes\DataProvider; |
24 | 23 | use PHPUnit\Framework\Attributes\Group; |
25 | 24 | use stdClass; |
@@ -209,64 +208,34 @@ public function testUpdateBatchValidationFail(): void |
209 | 208 | public function testUpdateBatchWithEntity(): void |
210 | 209 | { |
211 | 210 | $entity1 = new class () extends Entity { |
212 | | - protected int $id; |
213 | | - protected string $name; |
214 | | - protected string $email; |
215 | | - protected string $country; |
216 | | - protected bool $deleted; |
217 | | - protected DateTimeInterface $created_at; |
218 | | - protected DateTimeInterface $updated_at; |
219 | | - |
220 | | - /** |
221 | | - * @var array{'datamap': array{}, 'dates': array{string, string, string}, 'casts': array{}} |
222 | | - */ |
223 | | - protected $_options = [ |
224 | | - 'datamap' => [], |
225 | | - 'dates' => [ |
226 | | - 'created_at', |
227 | | - 'updated_at', |
228 | | - 'deleted_at', |
229 | | - ], |
230 | | - 'casts' => [], |
| 211 | + protected $attributes = [ |
| 212 | + 'id' => null, |
| 213 | + 'name' => null, |
| 214 | + 'country' => null, |
| 215 | + 'deleted_at' => null, |
231 | 216 | ]; |
232 | | - }; |
233 | | - |
234 | | - $entity2 = new class () extends Entity { |
235 | | - protected int $id; |
236 | | - protected string $name; |
237 | | - protected string $email; |
238 | | - protected string $country; |
239 | | - protected bool $deleted; |
240 | | - protected DateTimeInterface $created_at; |
241 | | - protected DateTimeInterface $updated_at; |
242 | | - |
243 | | - /** |
244 | | - * @var array{'datamap': array{}, 'dates': array{string, string, string}, 'casts': array{}} |
245 | | - */ |
246 | | - protected $_options = [ |
247 | | - 'datamap' => [], |
248 | | - 'dates' => [ |
249 | | - 'created_at', |
250 | | - 'updated_at', |
251 | | - 'deleted_at', |
252 | | - ], |
253 | | - 'casts' => [], |
| 217 | + protected $dates = [ |
| 218 | + 'created_at', |
| 219 | + 'updated_at', |
| 220 | + 'deleted_at', |
254 | 221 | ]; |
255 | 222 | }; |
256 | 223 |
|
257 | | - $entity1->id = 1; |
258 | | - $entity1->name = 'Jones Martin'; |
259 | | - $entity1->country = 'India'; |
260 | | - $entity1->deleted = 0; |
| 224 | + $entity2 = clone $entity1; |
| 225 | + |
| 226 | + $entity1->id = 1; |
| 227 | + $entity1->name = 'Jones Martin'; |
| 228 | + $entity1->country = 'India'; |
| 229 | + $entity1->deleted_at = null; |
261 | 230 | $entity1->syncOriginal(); |
262 | 231 | // Update the entity. |
263 | 232 | $entity1->country = 'China'; |
264 | 233 |
|
265 | 234 | // This entity is not updated. |
266 | | - $entity2->id = 4; |
267 | | - $entity2->name = 'Jones Martin'; |
268 | | - $entity2->country = 'India'; |
269 | | - $entity2->deleted = 0; |
| 235 | + $entity2->id = 4; |
| 236 | + $entity2->name = 'Jones Martin'; |
| 237 | + $entity2->country = 'India'; |
| 238 | + $entity2->deleted_at = null; |
270 | 239 | $entity2->syncOriginal(); |
271 | 240 |
|
272 | 241 | $model = $this->createModel(UserModel::class); |
@@ -408,33 +377,27 @@ public function testUpdateWithEntityNoAllowedFields(): void |
408 | 377 | $this->createModel(UserModel::class); |
409 | 378 |
|
410 | 379 | $entity = new class () extends Entity { |
411 | | - protected int $id; |
412 | | - protected string $name; |
413 | | - protected string $email; |
414 | | - protected string $country; |
415 | | - protected bool $deleted; |
416 | | - protected DateTimeInterface $created_at; |
417 | | - protected DateTimeInterface $updated_at; |
418 | | - |
419 | | - /** |
420 | | - * @var array{'datamap': array{}, 'dates': array{string, string, string}, 'casts': array{}} |
421 | | - */ |
422 | | - protected $_options = [ |
423 | | - 'datamap' => [], |
424 | | - 'dates' => [ |
425 | | - 'created_at', |
426 | | - 'updated_at', |
427 | | - 'deleted_at', |
428 | | - ], |
429 | | - 'casts' => [], |
| 380 | + protected $attributes = [ |
| 381 | + 'id' => null, |
| 382 | + 'name' => null, |
| 383 | + 'email' => null, |
| 384 | + 'country' => null, |
| 385 | + 'deleted_at' => null, |
| 386 | + 'created_at' => null, |
| 387 | + 'updated_at' => null, |
| 388 | + ]; |
| 389 | + protected $dates = [ |
| 390 | + 'created_at', |
| 391 | + 'updated_at', |
| 392 | + 'deleted_at', |
430 | 393 | ]; |
431 | 394 | }; |
432 | 395 |
|
433 | | - $entity->id = 1; |
434 | | - $entity->name = 'Jones Martin'; |
435 | | - $entity->email = 'jones@example.org'; |
436 | | - $entity->country = 'India'; |
437 | | - $entity->deleted = 0; |
| 396 | + $entity->id = 1; |
| 397 | + $entity->name = 'Jones Martin'; |
| 398 | + $entity->email = 'jones@example.org'; |
| 399 | + $entity->country = 'India'; |
| 400 | + $entity->deleted_at = null; |
438 | 401 |
|
439 | 402 | $id = $this->model->insert($entity); |
440 | 403 |
|
|
0 commit comments