Skip to content

Commit

Permalink
fix "must be scalar" ex for smallint/bigint
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed May 28, 2024
1 parent c5ee7e1 commit cddb296
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Persistence.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,12 +400,17 @@ private function _typecastPreField(Field $field, $value, bool $fromLoad)
switch ($field->type) {
case 'string':
case 'text':
case 'boolean':
case 'smallint':
case 'integer':
case 'bigint':
case 'float':
case 'decimal':
case 'atk4_money':
if (is_bool($value)) {
throw new Exception('Must not be bool type');
if ($field->type !== 'boolean') {
throw new Exception('Must not be bool type');
}
} elseif (is_int($value)) {
if ($fromLoad) {
$value = (string) $value;
Expand Down
29 changes: 29 additions & 0 deletions tests/FieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,35 @@ public function testNormalizeStringArrayException(): void
$m->set('foo', []);
}

/**
* @dataProvider provideNormalizeNumericNonScalarExceptionCases
*/
#[DataProvider('provideNormalizeNumericNonScalarExceptionCases')]
public function testNormalizeNumericNonScalarException(string $type): void
{
$m = new Model();
$m->addField('foo', ['type' => $type]);
$m = $m->createEntity();

$this->expectException(ValidationException::class);
$this->expectExceptionMessage('Must be scalar');
$m->set('foo', []);
}

/**
* @return iterable<list<mixed>>
*/
public static function provideNormalizeNumericNonScalarExceptionCases(): iterable
{
yield ['boolean'];
yield ['smallint'];
yield ['integer'];
yield ['bigint'];
yield ['float'];
yield ['decimal'];
yield ['atk4_money'];
}

public function testNormalizeStringBoolException(): void
{
$m = new Model();
Expand Down

0 comments on commit cddb296

Please sign in to comment.