From 87d076faa6b41694e7b21f9e2610cbd92e9d70b2 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Tue, 6 Jul 2021 16:43:54 +1200 Subject: [PATCH] FIX Cast DBInt value to int --- src/ORM/FieldType/DBInt.php | 9 +++++++++ tests/php/ORM/DBIntTest.php | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 tests/php/ORM/DBIntTest.php diff --git a/src/ORM/FieldType/DBInt.php b/src/ORM/FieldType/DBInt.php index f7863c813..eb283f4e9 100644 --- a/src/ORM/FieldType/DBInt.php +++ b/src/ORM/FieldType/DBInt.php @@ -20,6 +20,15 @@ class DBInt extends DBField parent::__construct($name); } + /** + * Ensure int values are always returned. + * This is for mis-configured databases that return strings. + */ + public function getValue() + { + return (int) $this->value; + } + /** * Returns the number, with commas added as appropriate, eg “1,000”. */ diff --git a/tests/php/ORM/DBIntTest.php b/tests/php/ORM/DBIntTest.php new file mode 100644 index 000000000..554d80232 --- /dev/null +++ b/tests/php/ORM/DBIntTest.php @@ -0,0 +1,18 @@ +setValue(3); + $this->assertSame(3, $field->getValue()); + $field->setValue('3'); + $this->assertSame(3, $field->getValue()); + } +}