diff --git a/src/Persistence.php b/src/Persistence.php index 3b2231dbb..7161140dd 100644 --- a/src/Persistence.php +++ b/src/Persistence.php @@ -361,7 +361,9 @@ private function _typecastPreField(Field $field, $value, bool $fromLoad) switch ($field->type) { case 'boolean': + case 'smallint': case 'integer': + case 'bigint': case 'float': case 'decimal': case 'atk4_money': diff --git a/tests/FieldTest.php b/tests/FieldTest.php index 2e3be5b99..f09b5f8b3 100644 --- a/tests/FieldTest.php +++ b/tests/FieldTest.php @@ -672,32 +672,14 @@ public function testNormalizeStringBoolException(): void $m->set('foo', false); } - public function testNormalizeIntegerNumericException(): void - { - $m = new Model(); - $m->addField('foo', ['type' => 'integer']); - $m = $m->createEntity(); - - $this->expectException(ValidationException::class); - $this->expectExceptionMessage('Must be numeric'); - $m->set('foo', '1x'); - } - - public function testNormalizeFloatNumericException(): void - { - $m = new Model(); - $m->addField('foo', ['type' => 'float']); - $m = $m->createEntity(); - - $this->expectException(ValidationException::class); - $this->expectExceptionMessage('Must be numeric'); - $m->set('foo', '1x'); - } - - public function testNormalizeAtk4MoneyNumericException(): void + /** + * @dataProvider provideRequiredNumericZeroExceptionCases + */ + #[DataProvider('provideRequiredNumericZeroExceptionCases')] + public function testNormalizeNumericException(string $type): void { $m = new Model(); - $m->addField('foo', ['type' => 'atk4_money']); + $m->addField('foo', ['type' => $type]); $m = $m->createEntity(); $this->expectException(ValidationException::class); @@ -705,15 +687,18 @@ public function testNormalizeAtk4MoneyNumericException(): void $m->set('foo', '1x'); } - public function testNormalizeBooleanNumericException(): void + /** + * @return iterable> + */ + public static function provideNormalizeNumericExceptionCases(): iterable { - $m = new Model(); - $m->addField('foo', ['type' => 'boolean']); - $m = $m->createEntity(); - - $this->expectException(ValidationException::class); - $this->expectExceptionMessage('Must be numeric'); - $m->set('foo', '1x'); + yield ['boolean']; + yield ['smallint']; + yield ['integer']; + yield ['bigint']; + yield ['float']; + yield ['decimal']; + yield ['atk4_money']; } public function testNormalizeDateException(): void