3 class QueryTest
extends PHPUnit_Framework_TestCase
10 for ($i=0; $i < 5000; $i++
) {
13 $c->str
= sha1(uniqid());
17 $this->assertEquals($c->count(), 5000);
32 /* prepare the query */
33 $c->properties('a,b')->where('a >', $val1)->where('b <', $val2)->where('c !=', $val3);
34 $c->where('h regexp', '/[a-f0-9]+/');
35 $c->where('x in', array(1, 2));
36 $c->where('x nin', array(4));
37 $c->where('y ==', array(4));
38 $c->sort('c DESC, a ASC')->limit($val4, $val5);
44 $sQuery = $c->getReference(true);
46 /* expected cursor info */
53 'a' => array('$gt' => $val1),
54 'b' => array('$lt' => $val2),
55 'c' => array('$ne' => $val3),
56 'h' => new MongoRegex('/[a-f0-9]+/'),
57 'x' => array('$in' => array(1,2), '$nin' => array(4)),
58 'y' => array('$all' => array(4)),
71 $this->assertEquals($sQuery['dynamic'], $eQuery);
75 function testQueryArray()
87 /* prepare the query */
92 'h regexp' => '/[a-f0-9]+/',
93 'x in ' => array(1,2),
97 $c->properties('a,b')->sort('c DESC, a ASC')->limit($val4, $val5);;
103 /* Get cursor info */
104 $sQuery = $c->getReference(true);
106 /* expected cursor info */
108 'ns' => DB
.'.model1',
113 'a' => array('$gt' => $val1),
114 'b' => array('$lt' => $val2),
115 'c' => array('$ne' => $val3),
116 'h' => new MongoRegex('/[a-f0-9]+/'),
117 'x' => array('$in' => array(1,2), '$nin' => array(4)),
118 'y' => array('$all' => array(4)),
131 $this->assertEquals($sQuery['dynamic'], $eQuery);
134 function testQueryRequireArray()
138 $c->where('c near', 'string');
139 $this->assertTrue(false);
140 } catch (ActiveMongo_Exception
$e) {
141 $this->assertTrue(true);
144 $c->where('c in', 55);
145 $this->assertTrue(false);
146 } catch (ActiveMongo_Exception
$e) {
147 $this->assertTrue(true);
150 $c->where('c nin', 559);
151 $this->assertTrue(false);
152 } catch (ActiveMongo_Exception
$e) {
153 $this->assertTrue(true);
157 function testMultipleOperationsPerProperty()
159 list($min, $max) = array(50, 100);
162 foreach ($c->where('int >', $min)->where('int <', $max) as $item) {
163 $this->assertGreaterThan($min, $item['int']);
164 $this->assertLessThan($max, $item['int']);
167 /* this could be done with a single regexp but
168 * this test should cover the multiple ALL amoung
171 * str regexp '//' AND str regexp '//' AND str regexp '//'
174 $c->where('str regex', '/^4/')->where('str regexp', '/a$/');
175 foreach ($c->where('str regex', '/[a-z0-9]+/') as $item) {
176 $this->assertEquals($item['str'][0], 4);
177 $this->assertEquals($item['str'][strlen($item['str'])-1], 'a');
182 $c->where('int >', $min)->where('int <', $max);
183 foreach ($c->where('int nin', array($min+
1, $min+
2, $min+
3)) as $item) {
184 $this->assertNotEquals($min+
1, $item['int']);
185 $this->assertNotEquals($min+
2, $item['int']);
186 $this->assertNotEquals($min+
3, $item['int']);
190 function testMultipleUpdate()
192 $str = sha1(uniqid());
200 $c->update(array('newproperty' => $str));
202 $c->where(array('int >' => 5, 'int <' => 30));
203 foreach ($c as $item) {
204 if ($item['int'] == 6) {
205 /* 6 is not included */
206 $this->assertFalse(isset($item['newproperty']));
208 $this->assertEquals($str, $item['newproperty']);
213 function testOnQueryModifyError()
220 $this->assertTrue(false);
221 } catch (ActiveMongo_Exception
$e) {
222 $this->assertTrue(true);
233 $this->assertLessThan($c->count(), 1);
234 foreach ($c as $item) {
235 $item_cloned = clone $item;
237 $item_cloned->save();
239 /* iterations are forbidden in cloned objects */
240 foreach ($item_cloned as $nitem) {
241 $this->assertTrue(false);
243 } catch (Exception
$e) {
244 $this->assertTrue(true);
249 function testDelete()
252 $c->where('int < ', 100);
255 $this->assertEquals($c->count(), 4900);