Skip to content

Commit

Permalink
add smallint/bigint "Must be numeric" ex
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed May 24, 2024
1 parent 2ff5838 commit 06a21f8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 32 deletions.
2 changes: 2 additions & 0 deletions src/Persistence.php
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
49 changes: 17 additions & 32 deletions tests/FieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -672,48 +672,33 @@ 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);
$this->expectExceptionMessage('Must be numeric');
$m->set('foo', '1x');
}

public function testNormalizeBooleanNumericException(): void
/**
* @return iterable<list<mixed>>
*/
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
Expand Down

0 comments on commit 06a21f8

Please sign in to comment.