- Added Exceptions file
[activemongo.git] / tests / QueryTest.php
blobb0ba69058a91226ea6ba8f432821e2aa15917acb
1 <?php
3 class QueryTest extends PHPUnit_Framework_TestCase
6 function testQuery()
8 $c = new Model1;
10 /* rand values */
11 $val1 = rand(1, 50);
12 $val2 = rand(1, 50);
13 $val3 = rand(1, 50);
14 $val4 = rand(1, 50);
15 $val5 = rand(1, 50);
18 /* prepare the query */
19 $c->properties('a,b')->where('a >', $val1)->where('b <', $val2)->where('c !=', $val3);
20 $c->sort('c DESC, a ASC')->limit($val4, $val5);
22 /* perform it */
23 $c->doQuery();
25 /* Get cursor info */
26 $sQuery = $c->getReference(true);
28 /* expected cursor info */
29 $eQuery = array(
30 'ns' => DB.'.model1',
31 'limit' => $val4,
32 'skip' => $val5,
33 'query' => array(
34 '$query' => array(
35 'a' => array('$gt' => $val1),
36 'b' => array('$lt' => $val2),
37 'c' => array('$ne' => $val3),
39 '$orderby' => array(
40 'c' => -1,
41 'a' => 1,
44 'fields' => array(
45 'a' => 1,
46 'b' => 1,
50 $this->assertEquals($sQuery['dynamic'], $eQuery);
53 function testOnQueryModifyError()
55 try {
56 $c = new Model1;
57 $c->where('a', 1);
58 $c->doQuery();
59 $c->where('b', 4);
60 $this->assertTrue(false);
61 } catch (ActiveMongo_Exception $e) {
62 $this->assertTrue(true);
66 function testClone()
68 $c = new Model1;
70 foreach ($c as $item) {
71 $item_cloned = clone $item;