1
0
mirror of synced 2024-12-13 14:56:01 +03:00

Fixed the core get() / set() issue

This commit is contained in:
zYne 2006-09-12 21:36:36 +00:00
parent 51fbbb05d6
commit 16d964e4ba
7 changed files with 107 additions and 93 deletions

View File

@ -551,8 +551,10 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
// delegate the loading operation to collections in which this record resides
foreach($this->collections as $collection) {
$collection->load($this);
}
} else {
$this->refresh();
}
$this->state = Doctrine_Record::STATE_CLEAN;
@ -575,34 +577,37 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$value = self::$null;
if(isset($this->data[$name])) {
// check if the property is null (= it is the Doctrine_Null object located in self::$null)
if($this->data[$name] === self::$null) {
$this->load();
if($this->data[$name] === self::$null)
$value = null;
} else
}
if($this->data[$name] === self::$null)
$value = null;
else
$value = $this->data[$name];
}
if(isset($this->id[$name]))
$value = $this->id[$name];
if($name === $this->table->getIdentifier())
$value = null;
if($value !== self::$null) {
if($invoke) {
if($invoke && $name !== $this->table->getIdentifier()) {
return $this->table->getAttribute(Doctrine::ATTR_LISTENER)->onGetProperty($this, $name, $value);
} else
return $value;
}
if(isset($this->id[$name]))
return $this->id[$name];
if($name === $this->table->getIdentifier())
return null;
if( ! isset($this->references[$name]))
$this->loadReference($name);

View File

@ -30,15 +30,16 @@ class Doctrine_EventListenerTestCase extends Doctrine_UnitTestCase {
$e->password = "123";
$this->assertEqual($e->get('name'), 'SOMETHING');
$this->assertEqual($e->get('name'), 'SOMETHING');
// test repeated calls
$this->assertEqual($e->get('name'), 'SOMETHING');
$this->assertEqual($e->id, null);
$this->assertEqual($e->rawGet('name'), 'something');
$this->assertEqual($e->password, '202cb962ac59075b964b07152d234b70');
$e->save();
$this->assertEqual($e->id, 1);
$this->assertEqual($e->name, 'SOMETHING');
$this->assertEqual($e->rawGet('name'), 'something');
$this->assertEqual($e->password, '202cb962ac59075b964b07152d234b70');
@ -47,6 +48,7 @@ class Doctrine_EventListenerTestCase extends Doctrine_UnitTestCase {
$e->refresh();
$this->assertEqual($e->id, 1);
$this->assertEqual($e->name, 'SOMETHING');
$this->assertEqual($e->rawGet('name'), 'something');
$this->assertEqual($e->password, '202cb962ac59075b964b07152d234b70');
@ -55,6 +57,7 @@ class Doctrine_EventListenerTestCase extends Doctrine_UnitTestCase {
$e = $e->getTable()->find($e->id);
$this->assertEqual($e->id, 1);
$this->assertEqual($e->name, 'SOMETHING');
$this->assertEqual($e->rawGet('name'), 'something');
$this->assertEqual($e->password, '202cb962ac59075b964b07152d234b70');

View File

@ -11,13 +11,13 @@ class Doctrine_ManagerTestCase extends Doctrine_UnitTestCase {
$this->assertTrue($this->manager->getIterator() instanceof ArrayIterator);
}
public function testCount() {
$this->assertEqual(count($this->manager),1);
$this->assertTrue(is_integer(count($this->manager)));
}
public function testGetCurrentConnection() {
$this->assertEqual($this->manager->getCurrentConnection(), $this->connection);
}
public function testGetConnections() {
$this->assertEqual(count($this->manager->getConnections()),1);
$this->assertTrue(is_integer(count($this->manager->getConnections())));
}
public function testClassifyTableize() {
$name = "Forum_Category";

View File

@ -24,6 +24,68 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
parent::prepareTables();
}
public function testManyToManyFetchingWithColumnAggregationInheritance() {
$query = new Doctrine_Query($this->connection);
$query->from('User-l:Group-l');
$users = $query->execute();
$this->assertEqual($users->count(), 1);
$this->assertEqual($users[0]->Group->count(), 1);
$query->from('User-l.Group-l');
$users = $query->execute();
$this->assertEqual($users->count(), 8);
$this->assertEqual($users[0]->Group->count(), 0);
$this->assertEqual($users[1]->Group->count(), 1);
$this->assertEqual($users[2]->Group->count(), 0);
$this->assertEqual($users[0]->getState(), Doctrine_Record::STATE_PROXY);
$this->assertEqual($users[1]->getState(), Doctrine_Record::STATE_PROXY);
$this->assertEqual($users[2]->getState(), Doctrine_Record::STATE_PROXY);
$this->assertEqual($users[0]->getModified(), array());
$this->assertEqual($users[1]->getModified(), array());
$this->assertEqual($users[2]->getModified(), array());
$this->assertEqual($users[6]->getModified(), array());
$this->assertEqual($users[0]->type, 0);
$this->assertEqual($users[1]->type, 0);
$this->assertEqual($users[2]->type, 0);
$this->connection->flush();
$users = $query->query("FROM User-b WHERE User.Group.name = 'Action Actors'");
$this->assertEqual(trim($query->getQuery()),
"SELECT entity.id AS entity__id FROM entity LEFT JOIN groupuser ON entity.id = groupuser.user_id LEFT JOIN entity AS entity2 ON entity2.id = groupuser.group_id WHERE entity2.name = 'Action Actors' AND (entity.type = 0 AND (entity2.type = 1 OR entity2.type IS NULL))");
$this->assertTrue($users instanceof Doctrine_Collection);
$this->assertEqual($users->count(),1);
$this->assertEqual(count($this->dbh->query($query->getQuery())->fetchAll()),1);
$users = $query->query("FROM User-b WHERE User.Group.Phonenumber.phonenumber LIKE '123 123'");
$this->assertEqual(trim($query->getQuery()),
"SELECT entity.id AS entity__id FROM entity LEFT JOIN groupuser ON entity.id = groupuser.user_id LEFT JOIN entity AS entity2 ON entity2.id = groupuser.group_id LEFT JOIN phonenumber ON entity2.id = phonenumber.entity_id WHERE phonenumber.phonenumber LIKE '123 123' AND (entity.type = 0 AND (entity2.type = 1 OR entity2.type IS NULL))");
$this->assertTrue($users instanceof Doctrine_Collection);
$this->assertEqual($users->count(),1);
$query = new Doctrine_Query();
$users = $query->query("FROM User.Group WHERE User.Group.name = 'Action Actors'");
$this->assertEqual($users->count(), 1);
$count = $this->dbh->count();
$this->assertTrue($users instanceof Doctrine_Collection);
$this->assertEqual(get_class($users[0]), 'User');
$this->assertEqual($users[0]->Group->count(), 1);
$this->assertEqual($count, $this->dbh->count());
$this->assertEqual($users[0]->Group[0]->name, 'Action Actors');
$this->assertEqual($count, $this->dbh->count());
}
public function testSelectingAggregateValues() {
$q = new Doctrine_Query();
@ -64,14 +126,14 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
$this->assertEqual($array[0]['MAX(entity.id)'], 11);
$this->assertEqual($array[0]['MIN(email.address)'], 'arnold@example.com');
$this->assertEqual($array[0]['COUNT(1)'], 14);
/**
$q = new Doctrine_Query();
$q->from("User.Phonenumber(COUNT(id))")->groupby("User.id");
$coll = $q->execute();
print Doctrine_Lib::formatSql($q->getQuery());
print_r($coll);
$this->assertEqual(count($coll), 8);
*/
//$q = new Doctrine_Query();
//$q->from("User.Phonenumber(COUNT(id))")->groupby("User.id");
//$coll = $q->execute();
//print Doctrine_Lib::formatSql($q->getQuery());
//print_r($coll);
//$this->assertEqual(count($coll), 8);
}
@ -359,65 +421,7 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
$this->assertEqual($users[2]->id, 10);
}
public function testManyToManyFetchingWithColumnAggregationInheritance() {
$query = new Doctrine_Query($this->connection);
$query->from('User-l:Group-l');
$users = $query->execute();
$this->assertEqual($users->count(), 1);
$this->assertEqual($users[0]->Group->count(), 1);
$query->from('User-l.Group-l');
$users = $query->execute();
$this->assertEqual($users->count(), 8);
$this->assertEqual($users[0]->Group->count(), 0);
$this->assertEqual($users[1]->Group->count(), 1);
$this->assertEqual($users[2]->Group->count(), 0);
$this->assertEqual($users[0]->getState(), Doctrine_Record::STATE_PROXY);
$this->assertEqual($users[1]->getState(), Doctrine_Record::STATE_PROXY);
$this->assertEqual($users[2]->getState(), Doctrine_Record::STATE_PROXY);
$this->assertEqual($users[0]->getModified(), array());
$this->assertEqual($users[1]->getModified(), array());
$this->assertEqual($users[2]->getModified(), array());
$this->assertEqual($users[6]->getModified(), array());
$this->assertEqual($users[0]->type, 0);
$this->assertEqual($users[1]->type, 0);
$this->assertEqual($users[2]->type, 0);
$this->connection->flush();
$users = $query->query("FROM User-b WHERE User.Group.name = 'Action Actors'");
$this->assertEqual(trim($query->getQuery()),
"SELECT entity.id AS entity__id FROM entity LEFT JOIN groupuser ON entity.id = groupuser.user_id LEFT JOIN entity AS entity2 ON entity2.id = groupuser.group_id WHERE entity2.name = 'Action Actors' AND (entity.type = 0 AND (entity2.type = 1 OR entity2.type IS NULL))");
$this->assertTrue($users instanceof Doctrine_Collection);
$this->assertEqual($users->count(),1);
$this->assertEqual(count($this->dbh->query($query->getQuery())->fetchAll()),1);
$users = $query->query("FROM User-b WHERE User.Group.Phonenumber.phonenumber LIKE '123 123'");
$this->assertEqual(trim($query->getQuery()),
"SELECT entity.id AS entity__id FROM entity LEFT JOIN groupuser ON entity.id = groupuser.user_id LEFT JOIN entity AS entity2 ON entity2.id = groupuser.group_id LEFT JOIN phonenumber ON entity2.id = phonenumber.entity_id WHERE phonenumber.phonenumber LIKE '123 123' AND (entity.type = 0 AND (entity2.type = 1 OR entity2.type IS NULL))");
$this->assertTrue($users instanceof Doctrine_Collection);
$this->assertEqual($users->count(),1);
$users = $query->query("FROM User.Group WHERE User.Group.name = 'Action Actors'");
$this->assertEqual($users->count(), 1);
$count = $this->dbh->count();
$this->assertTrue($users instanceof Doctrine_Collection);
$this->assertEqual(get_class($users[0]), 'User');
$this->assertEqual($users[0]->Group->count(), 1);
$this->assertEqual($count, $this->dbh->count());
$this->assertEqual($users[0]->Group[0]->name, 'Action Actors');
$this->assertEqual($count, $this->dbh->count());
}
public function testNestedManyToManyRelations() {
$task = new Task();

View File

@ -67,14 +67,13 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
$this->assertEqual(count($result), 6);
/**
$stmt = $this->dbh->prepare($q);
//$stmt = $this->dbh->prepare($q);
$stmt->execute(array(18));
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
//$stmt->execute(array(18));
//$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
//print_r($result);
print_r($result);
*/
$this->connection->clear();
$e = $e->getTable()->find($e->id);
@ -122,7 +121,6 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
}
public function testToArray() {
$user = new User();
@ -256,6 +254,8 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
$enum->refresh();
$this->assertEqual($enum->status, "closed");
$this->dbh->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL);
}
public function testFailingRefresh() {
$enum = $this->connection->getTable('EnumTest')->find(1);
@ -269,7 +269,8 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
$f = true;
}
$this->assertTrue($f);
}
}
public function testSerialize() {
$user = $this->connection->getTable("User")->find(4);
$str = serialize($user);
@ -357,7 +358,6 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
$this->assertEqual($coll->count(), 1);
}
public function testManyToManyTreeStructure() {
$task = $this->connection->create("Task");
@ -898,6 +898,7 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
$this->assertEqual($user->Groupuser[1]->added, $t2);
}
public function testCount() {
$user = $this->connection->getTable("User")->find(4);
@ -917,6 +918,5 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
$user = $this->connection->getTable("User")->find(4);
$this->assertTrue($user->getIterator() instanceof ArrayIterator);
}
}
?>

View File

@ -52,6 +52,8 @@ class Doctrine_TableTestCase extends Doctrine_UnitTestCase {
$this->assertEqual($t->someInt, 1);
$this->assertEqual($t->someArray, array());
$this->assertEqual($t->someObject, $obj);
$this->dbh->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL);
}
public function testBind() {
$table = $this->connection->getTable("User");

View File

@ -42,7 +42,7 @@ $test->addTestCase(new Doctrine_ConnectionTestCase());
$test->addTestCase(new Doctrine_ManagerTestCase());
$test->addTestCase(new Doctrine_AccessTestCase());
$test->addTestCase(new Doctrine_AccessTestCase());
$test->addTestCase(new Doctrine_BatchIteratorTestCase());