|
13 | 13 | use Tempest\Database\Migrations\CreateMigrationsTable; |
14 | 14 | use Tempest\Mapper\CasterFactory; |
15 | 15 | use Tempest\Mapper\SerializerFactory; |
| 16 | +use Tempest\Validation\Exceptions\ValidationException; |
16 | 17 | use Tests\Tempest\Fixtures\Migrations\CreateAuthorTable; |
17 | 18 | use Tests\Tempest\Fixtures\Migrations\CreateBookTable; |
18 | 19 | use Tests\Tempest\Fixtures\Models\A; |
|
42 | 43 | use Tests\Tempest\Integration\ORM\Models\CasterEnum; |
43 | 44 | use Tests\Tempest\Integration\ORM\Models\CasterModel; |
44 | 45 | use Tests\Tempest\Integration\ORM\Models\ChildModel; |
| 46 | +use Tests\Tempest\Integration\ORM\Models\ModelWithValidation; |
45 | 47 | use Tests\Tempest\Integration\ORM\Models\ParentModel; |
46 | 48 | use Tests\Tempest\Integration\ORM\Models\StaticMethodTableNameModel; |
47 | 49 | use Tests\Tempest\Integration\ORM\Models\ThroughModel; |
@@ -540,4 +542,27 @@ public function test_table_name_overrides(): void |
540 | 542 | $this->assertEquals('custom_attribute_table_name', new ModelDefinition(AttributeTableNameModel::class)->getTableDefinition()->name); |
541 | 543 | $this->assertEquals('custom_static_method_table_name', new ModelDefinition(StaticMethodTableNameModel::class)->getTableDefinition()->name); |
542 | 544 | } |
| 545 | + |
| 546 | + public function test_validation_on_create(): void |
| 547 | + { |
| 548 | + $this->expectException(ValidationException::class); |
| 549 | + |
| 550 | + ModelWithValidation::create( |
| 551 | + index: -1, |
| 552 | + ); |
| 553 | + } |
| 554 | + |
| 555 | + public function test_validation_on_update(): void |
| 556 | + { |
| 557 | + $model = ModelWithValidation::new( |
| 558 | + id: new Id(1), |
| 559 | + index: 1, |
| 560 | + ); |
| 561 | + |
| 562 | + $this->expectException(ValidationException::class); |
| 563 | + |
| 564 | + $model->update( |
| 565 | + index: -1, |
| 566 | + ); |
| 567 | + } |
543 | 568 | } |
0 commit comments