3 class ReferencesTest
extends PHPUnit_Framework_TestCase
5 public function testReferences()
18 $this->assertEquals($c->getReference(), $ref);
22 /* Reference into a document */
24 /* References into sub documents */
25 $d->nested
= array($c, $c);
26 /* Get Dynamic query; AKA save the query */
27 /* in this case it would be a get all */
29 $query->where('a', 'foobar');
31 $d->query
= $query->getReference(TRUE);
38 * @depends testReferences
40 public function testReferenceSave()
43 $d->where('a', 'barfoo');
45 foreach ($d as $doc) {
46 $this->assertTrue(isset($doc->next
));
47 $this->assertTrue(MongoDBRef
::isRef($doc->next
));
48 $this->assertTrue(MongoDBRef
::isRef($doc->nested
[0]));
49 $this->assertTrue(MongoDBRef
::isRef($doc->nested
[1]));
50 $this->assertTrue(MongoDBRef
::isRef($doc->query
));
52 /* Check dynamic references properties */
53 $this->assertTrue(is_array($doc->query
['dynamic']));
54 $this->assertTrue(count($doc->query
['dynamic']) > 0);
57 $doc->doDeferencing();
60 $this->assertTrue($doc->next
InstanceOf Model1
);
61 $this->assertTrue($doc->nested
[0] InstanceOf Model1
);
62 $this->assertTrue($doc->nested
[1] InstanceOf Model1
);
63 $this->assertTrue(is_array($doc->query
));
64 $this->assertTrue($doc->query
[0] InstanceOf Model1
);
66 /* Testing Iteration in defered documents */
67 /* They should fail because they are cloned */
68 /* instances of a real document */
71 $this->assertTrue(FALSE);
72 } catch (ActiveMongo_Exception
$e) {
73 $this->assertTrue(TRUE);