2006-08-07 13:55:46 +04:00
|
|
|
<?php
|
|
|
|
require_once("UnitTestCase.php");
|
|
|
|
|
|
|
|
class Doctrine_ValueHolder_TestCase extends Doctrine_UnitTestCase {
|
|
|
|
public function testGetSet() {
|
|
|
|
$this->valueHolder->data[0] = 'first';
|
|
|
|
|
|
|
|
$this->assertEqual($this->valueHolder->data[0], 'first');
|
|
|
|
$this->assertEqual($this->valueHolder[0], 'first');
|
|
|
|
$this->assertEqual($this->valueHolder->get(0), 'first');
|
|
|
|
|
|
|
|
$this->valueHolder->data['key'] = 'second';
|
|
|
|
|
|
|
|
$this->assertEqual($this->valueHolder->data['key'], 'second');
|
|
|
|
$this->assertEqual($this->valueHolder->key, 'second');
|
|
|
|
$this->assertEqual($this->valueHolder['key'], 'second');
|
|
|
|
$this->assertEqual($this->valueHolder->get('key'), 'second');
|
|
|
|
}
|
|
|
|
public function testSimpleQuery() {
|
2006-08-22 03:20:33 +04:00
|
|
|
$q = new Doctrine_Query($this->connection);
|
2006-08-07 13:55:46 +04:00
|
|
|
$q->from("User");
|
2006-08-20 22:52:07 +04:00
|
|
|
$users = $q->execute(array(), Doctrine::FETCH_VHOLDER);
|
2006-08-07 13:55:46 +04:00
|
|
|
$this->assertEqual($users->count(), 8);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
public function testQueryWithOneToManyRelation() {
|
2006-08-22 03:20:33 +04:00
|
|
|
$q = new Doctrine_Query($this->connection);
|
2006-08-07 13:55:46 +04:00
|
|
|
$q->from("User.Phonenumber");
|
2006-08-20 22:52:07 +04:00
|
|
|
$users = $q->execute(array(), Doctrine::FETCH_VHOLDER);
|
2006-08-07 13:55:46 +04:00
|
|
|
$this->assertEqual($users->count(), 8);
|
|
|
|
$this->assertTrue($users[0] instanceof Doctrine_ValueHolder);
|
|
|
|
$this->assertTrue($users[3] instanceof Doctrine_ValueHolder);
|
|
|
|
$this->assertTrue($users[7] instanceof Doctrine_ValueHolder);
|
|
|
|
|
|
|
|
$this->assertEqual(count($users[0]->Phonenumber), 1);
|
|
|
|
$this->assertEqual(count($users[1]->Phonenumber), 3);
|
|
|
|
$this->assertEqual(count($users[2]->Phonenumber), 1);
|
|
|
|
$this->assertEqual(count($users[3]->Phonenumber), 1);
|
|
|
|
$this->assertEqual(count($users[4]->Phonenumber), 3);
|
|
|
|
}
|
|
|
|
public function testDelete() {
|
|
|
|
$f = false;
|
|
|
|
try {
|
|
|
|
$this->valueHolder->delete();
|
|
|
|
} catch(Doctrine_Exception $e) {
|
|
|
|
$f = true;
|
|
|
|
}
|
|
|
|
$this->assertTrue($f);
|
|
|
|
}
|
|
|
|
public function testSave() {
|
|
|
|
$f = false;
|
|
|
|
try {
|
|
|
|
$this->valueHolder->save();
|
|
|
|
} catch(Doctrine_Exception $e) {
|
|
|
|
$f = true;
|
|
|
|
}
|
|
|
|
$this->assertTrue($f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|