mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FIX Cast DBInt value to int
This commit is contained in:
parent
e8c14a9d5b
commit
87d076faa6
@ -20,6 +20,15 @@ class DBInt extends DBField
|
|||||||
parent::__construct($name);
|
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”.
|
* Returns the number, with commas added as appropriate, eg “1,000”.
|
||||||
*/
|
*/
|
||||||
|
18
tests/php/ORM/DBIntTest.php
Normal file
18
tests/php/ORM/DBIntTest.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\ORM\Tests;
|
||||||
|
|
||||||
|
use SilverStripe\Dev\SapphireTest;
|
||||||
|
use SilverStripe\ORM\FieldType\DBInt;
|
||||||
|
|
||||||
|
class DBIntTest extends SapphireTest
|
||||||
|
{
|
||||||
|
public function testGetValueCastToInt()
|
||||||
|
{
|
||||||
|
$field = DBInt::create('MyField');
|
||||||
|
$field->setValue(3);
|
||||||
|
$this->assertSame(3, $field->getValue());
|
||||||
|
$field->setValue('3');
|
||||||
|
$this->assertSame(3, $field->getValue());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user