3 namespace Doctrine\Tests\ORM\Persisters;
5 use Doctrine\DBAL\Types\Type as DBALType;
6 use Doctrine\ORM\Persisters\BasicEntityPersister;
7 use Doctrine\Tests\Models\CustomType\CustomTypeParent;
8 use Doctrine\Tests\Models\CustomType\CustomTypeChild;
9 use Doctrine\Tests\Models\CustomType\CustomTypeFriend;
11 require_once __DIR__ . '/../../TestInit.php';
13 class BasicEntityPersisterTypeValueSqlTest extends \Doctrine\Tests\OrmTestCase
15 protected $_persister;
18 protected function setUp()
22 if (DBALType::hasType('negative_to_positive')) {
23 DBALType::overrideType('negative_to_positive', '\Doctrine\Tests\DbalTypes\NegativeToPositiveType');
25 DBALType::addType('negative_to_positive', '\Doctrine\Tests\DbalTypes\NegativeToPositiveType');
28 if (DBALType::hasType('upper_case_string')) {
29 DBALType::overrideType('upper_case_string', '\Doctrine\Tests\DbalTypes\UpperCaseStringType');
31 DBALType::addType('upper_case_string', '\Doctrine\Tests\DbalTypes\UpperCaseStringType');
34 $this->_em = $this->_getTestEntityManager();
36 $this->_persister = new BasicEntityPersister($this->_em, $this->_em->getClassMetadata("Doctrine\Tests\Models\CustomType\CustomTypeParent"));
39 public function testGetInsertSQLUsesTypeValuesSQL()
41 $method = new \ReflectionMethod($this->_persister, '_getInsertSQL');
42 $method->setAccessible(true);
44 $sql = $method->invoke($this->_persister);
46 $this->assertEquals('INSERT INTO customtype_parents (customInteger, child_id) VALUES (ABS(?), ?)', $sql);
49 public function testUpdateUsesTypeValuesSQL()
51 $child = new CustomTypeChild();
53 $parent = new CustomTypeParent();
54 $parent->customInteger = 1;
55 $parent->child = $child;
57 $this->_em->getUnitOfWork()->registerManaged($parent, array('id' => 1), array('customInteger' => 0, 'child' => null));
58 $this->_em->getUnitOfWork()->registerManaged($child, array('id' => 1), array());
60 $this->_em->getUnitOfWork()->propertyChanged($parent, 'customInteger', 0, 1);
61 $this->_em->getUnitOfWork()->propertyChanged($parent, 'child', null, $child);
63 $this->_persister->update($parent);
65 $executeUpdates = $this->_em->getConnection()->getExecuteUpdates();
67 $this->assertEquals('UPDATE customtype_parents SET customInteger = ABS(?), child_id = ? WHERE id = ?', $executeUpdates[0]['query']);
70 public function testGetSelectConditionSQLUsesTypeValuesSQL()
72 $method = new \ReflectionMethod($this->_persister, '_getSelectConditionSQL');
73 $method->setAccessible(true);
75 $sql = $method->invoke($this->_persister, array('customInteger' => 1, 'child' => 1));
77 $this->assertEquals('t0.customInteger = ABS(?) AND t0.child_id = ?', $sql);
83 public function testStripNonAlphanumericCharactersFromSelectColumnListSQL()
85 $persister = new BasicEntityPersister($this->_em, $this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\SimpleEntity'));
86 $method = new \ReflectionMethod($persister, '_getSelectColumnListSQL');
87 $method->setAccessible(true);
89 $this->assertEquals('t0."simple-entity-id" AS simpleentityid1, t0."simple-entity-value" AS simpleentityvalue2', $method->invoke($persister));