mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUG Implement peer review feedback,
This commit is contained in:
parent
9a59f2f57d
commit
6ff319a0e1
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace SilverStripe\ORM\Tests\DataObjectTest;
|
namespace SilverStripe\ORM\Tests\DataObjectTest;
|
||||||
|
|
||||||
|
use SilverStripe\Dev\TestOnly;
|
||||||
use SilverStripe\ORM\FieldType\DBBoolean;
|
use SilverStripe\ORM\FieldType\DBBoolean;
|
||||||
use SilverStripe\ORM\FieldType\DBField;
|
use SilverStripe\ORM\FieldType\DBField;
|
||||||
|
|
||||||
@ -13,16 +14,16 @@ use SilverStripe\ORM\FieldType\DBField;
|
|||||||
* If the field is set to false, it will try to do a plain assignment. This is so you can save the initial value no
|
* If the field is set to false, it will try to do a plain assignment. This is so you can save the initial value no
|
||||||
* matter what. If the field is set to true, it will try to do a dynamic assignment.
|
* matter what. If the field is set to true, it will try to do a dynamic assignment.
|
||||||
*/
|
*/
|
||||||
class MockDynamicAssignmentDBField extends DBBoolean
|
class MockDynamicAssignmentDBField extends DBBoolean implements TestOnly
|
||||||
{
|
{
|
||||||
|
|
||||||
private $scalarOnly;
|
private $scalarOnly;
|
||||||
private $dynamicAssignment;
|
private $dynamicAssignment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $name
|
* @param string $name
|
||||||
* @param $scalarOnly Whether our fake field should be scalar only
|
* @param boolean $scalarOnly Whether our fake field should be scalar only.
|
||||||
* @param $dynamicAssigment Wheter our fake field will try to do a dynamic assignement
|
* @param boolean $dynamicAssignment Whether our fake field will try to do a dynamic assignment.
|
||||||
*/
|
*/
|
||||||
public function __construct($name = '', $scalarOnly = false, $dynamicAssignment = false)
|
public function __construct($name = '', $scalarOnly = false, $dynamicAssignment = false)
|
||||||
{
|
{
|
||||||
@ -32,15 +33,15 @@ class MockDynamicAssignmentDBField extends DBBoolean
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the field value and dynamicAssignment are true, we'll try to do a dynamic assignement
|
* If the field value and $dynamicAssignment are true, we'll try to do a dynamic assignment.
|
||||||
* @param $value
|
* @param $value
|
||||||
* @return array|int|mixed
|
* @return array|int
|
||||||
*/
|
*/
|
||||||
public function prepValueForDB($value)
|
public function prepValueForDB($value)
|
||||||
{
|
{
|
||||||
if ($value) {
|
if ($value) {
|
||||||
return $this->dynamicAssignment
|
return $this->dynamicAssignment
|
||||||
? ['GREATEST(?, ?)' => [0, 1]]
|
? ['ABS(?)' => [1]]
|
||||||
: 1;
|
: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,11 +30,11 @@ class MockDynamicAssignmentDataObject extends DataObject implements TestOnly
|
|||||||
];
|
];
|
||||||
|
|
||||||
private static $many_many = [
|
private static $many_many = [
|
||||||
"MockManyMany" => self::class,
|
'MockManyMany' => self::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
private static $belongs_many_many = [
|
private static $belongs_many_many = [
|
||||||
"MockBelongsManyMany" => self::class,
|
'MockBelongsManyMany' => self::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
private static $many_many_extraFields = [
|
private static $many_many_extraFields = [
|
||||||
|
@ -10,6 +10,7 @@ use SilverStripe\ORM\Tests\DataObjectTest\Player;
|
|||||||
use SilverStripe\ORM\Tests\DataObjectTest\Team;
|
use SilverStripe\ORM\Tests\DataObjectTest\Team;
|
||||||
use SilverStripe\ORM\Tests\ManyManyListTest\ExtraFieldsObject;
|
use SilverStripe\ORM\Tests\ManyManyListTest\ExtraFieldsObject;
|
||||||
use SilverStripe\ORM\Tests\ManyManyListTest\Product;
|
use SilverStripe\ORM\Tests\ManyManyListTest\Product;
|
||||||
|
use InvalidArgumentException;
|
||||||
|
|
||||||
class ManyManyListTest extends SapphireTest
|
class ManyManyListTest extends SapphireTest
|
||||||
{
|
{
|
||||||
@ -402,7 +403,7 @@ class ManyManyListTest extends SapphireTest
|
|||||||
|
|
||||||
public function testWriteManipulationWithNonScalarValuesDisallowed()
|
public function testWriteManipulationWithNonScalarValuesDisallowed()
|
||||||
{
|
{
|
||||||
$this->expectException(\InvalidArgumentException::class);
|
$this->expectException(InvalidArgumentException::class);
|
||||||
|
|
||||||
$left = DataObjectTest\MockDynamicAssignmentDataObject::create();
|
$left = DataObjectTest\MockDynamicAssignmentDataObject::create();
|
||||||
$left->write();
|
$left->write();
|
||||||
|
Loading…
Reference in New Issue
Block a user