mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #10009 from creative-commoners/pulls/4.8/treedropdown-pdo
FIX Cast DBInt value to int
This commit is contained in:
commit
2e5908cf21
@ -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”.
|
||||
*/
|
||||
|
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