ValueHolderTestCase.php 2.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
<?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() {
zYne's avatar
zYne committed
20
        $q = new Doctrine_Query($this->connection);
21
        $q->from("User");
22
        $users = $q->execute(array(), Doctrine::FETCH_VHOLDER);
23 24 25 26 27
        $this->assertEqual($users->count(), 8);


    }
    public function testQueryWithOneToManyRelation() {
zYne's avatar
zYne committed
28
        $q = new Doctrine_Query($this->connection);
29
        $q->from("User.Phonenumber");
30
        $users = $q->execute(array(), Doctrine::FETCH_VHOLDER);
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
        $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);
    }
}