- Added more function to ActiveMongo (getArray(), servedFromCache())
[activemongo.git] / tests / ArrayTest.php
blob91d3bfca3ca51323563ecf15b494de56bd64c2dd
1 <?php
3 class ArrayTest extends PHPUnit_Framework_TestCase
6 function testCount()
8 $m1 = new Model1;
9 $m2 = new Model2;
11 $this->assertEquals($m1->count(), count($m1));
12 $this->assertEquals($m2->count(), count($m2));
15 function testArrayAccess()
17 $m2 = new Model2;
19 foreach ($m2 as $item) {
20 $this->assertFalse(isset($item['foobar']));
21 $this->assertTrue(isset($item['a']));
22 $this->assertEquals($item['a'], $item->a);
23 $item['foobar'] = rand(1, 1000);
24 $this->assertEquals($item['foobar'], $item->foobar);
28 function testUnsetIsset()
30 $c = new Model1;
31 $c['a'] = 5;
32 $this->assertTrue(isset($c['a']));
33 unset($c['a']);
34 $this->assertFalse(isset($c['a']));
37 function testScalarToArray()
39 $c = new Model1;
40 $c->a = 1;
41 $c->save();
42 $c->a = array(1, 2);
43 $c->save();
44 $c->a[0] = array(1,2);
45 $c->a[1] = 3;
46 $c->save();
48 $id = $c->getID();
51 $c->reset();
52 $c->where('_id', $id);
53 $c->doQuery();
55 $this->assertEquals(array(array(1,2), 3), $c->a);
59 function testArrayUnsetNull()
61 $arr = array(1,2,3,4);
62 $doc = new Dummy;
63 $doc->arr = $arr;
64 $doc->save();
65 unset($arr[1], $arr[3]);
66 $doc->arr = $arr;
67 $doc->save();
69 $this->assertEquals($arr, $doc->arr);