1
0
mirror of synced 2024-12-15 15:46:02 +03:00
doctrine2/tests/ValueHolderTestCase.php

61 lines
2.2 KiB
PHP
Raw Normal View History

<?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);
$q->from("User");
$users = $q->execute(array(), Doctrine::FETCH_VHOLDER);
$this->assertEqual($users->count(), 8);
}
public function testQueryWithOneToManyRelation() {
2006-08-22 03:20:33 +04:00
$q = new Doctrine_Query($this->connection);
$q->from("User.Phonenumber");
$users = $q->execute(array(), Doctrine::FETCH_VHOLDER);
$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);
}
}