Skip to content

Commit

Permalink
fix whitespace/comma removal for smallint/bigint
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed May 28, 2024
1 parent 8c03a8c commit f3aadbf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Persistence.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,9 @@ private function _typecastPreField(Field $field, $value, bool $fromLoad)
if (is_string($value)) {
switch ($field->type) {
case 'boolean':
case 'smallint':
case 'integer':
case 'bigint':
$value = preg_replace('~\s+|,~', '', $value);

break;
Expand Down
8 changes: 8 additions & 0 deletions tests/FieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,9 @@ public function testNormalize(): void

$m->addField('string', ['type' => 'string']);
$m->addField('text', ['type' => 'text']);
$m->addField('smallint', ['type' => 'smallint']);
$m->addField('integer', ['type' => 'integer']);
$m->addField('bigint', ['type' => 'bigint']);
$m->addField('money', ['type' => 'atk4_money']);
$m->addField('float', ['type' => 'float']);
$m->addField('boolean', ['type' => 'boolean']);
Expand Down Expand Up @@ -645,9 +647,15 @@ public function testNormalize(): void
self::assertSame("Two\nLines", $m->get('text'));

// integer, money, float
$m->set('smallint', '12,345.67676767');
self::assertSame(12345, $m->get('smallint'));

$m->set('integer', '12,345.67676767');
self::assertSame(12345, $m->get('integer'));

$m->set('bigint', '12,345.67676767');
self::assertSame(12345, (int) $m->get('bigint')); // once DBAL 3.x support is dropped, the explicit cast should no longer be needed

$m->set('money', '12,345.67676767');
self::assertSame(12345.6768, $m->get('money'));

Expand Down

0 comments on commit f3aadbf

Please sign in to comment.