File: MongoTest.php

package info (click to toggle)
php-mongo 1.5.7-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 11,040 kB
  • ctags: 2,802
  • sloc: ansic: 17,632; xml: 2,195; php: 1,630; pascal: 330; makefile: 52; sh: 39
file content (741 lines) | stat: -rw-r--r-- 22,150 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
<?php
/**
 * Test class for Mongo.
 * Generated by PHPUnit on 2009-04-09 at 18:09:02.
 */
class MongoTest extends PHPUnit_Framework_TestCase
{
    /**
     * @var    Mongo
     * @access protected
     */
    protected $object;

    /**
     * Sets up the fixture, for example, opens a network connection.
     * This method is called before a test is executed.
     *
     * @access protected
     */
    public function setUp() {
        $this->object = new Mongo("localhost", array("connect" => false));
    }

    public function testBrokenConnect() {
		try {
			$this->object = new Mongo("localhost", false);
		} catch (PHPUnit_Framework_Error $e) {
			$this->assertEquals("Argument 2 passed to Mongo::__construct() must be an array, boolean given", $e->getMessage());
		}
        $this->assertFalse($this->object->connected);
    }

    public function testConnect() {
        $this->object->connect();
        $this->assertTrue($this->object->connected);

        $this->object->close();
        $this->assertFalse($this->object->connected);

        $this->object->connect();
        $x = $this->object->connect();
        $this->assertTrue($this->object->connected);
        $this->assertTrue($x);
    }

    public function testConnect2() {
        $this->object = new Mongo("localhost", array("connect" => false));
        $this->assertFalse($this->object->connected);
    }

    public function testSpaceChomp() {
      $m = new Mongo("localhost:27018, localhost");
      $m = new Mongo("localhost:27018,    localhost, localhost:27019");
      $m = new Mongo("localhost:27018, localhost, ");
    }

    /**
     * @expectedException MongoConnectionException
     */
    public function testDumbIPs2() {
	$m = new Mongo(":,:");
    }

    /**
     * @expectedException MongoConnectionException
     */
    public function testDumbIPs3() {
	$m = new Mongo("x:x");
    }

    /**
     * @expectedException MongoConnectionException
     */
    public function testDumbIPs4() {
	$m = new Mongo("localhost:");
    }

    // these should actually work, though
    public function testDumbIPs5() {
	$m = new Mongo("localhost,localhost");
	$m = new Mongo("localhost,localhost:27");
	$m = new Mongo("localhost:27017,localhost:27018,");
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testPersistConnect() {
        $m1 = new Mongo("localhost:27017", false);
        $m1->persistConnect("", "");

        $m2 = new Mongo("localhost:27017", false);
        $m2->persistConnect("", "");

        // make sure this doesn't disconnect $m2
        unset($m1);

        $c = $m2->selectCollection("phpunit","bar");
        $c->findOne();
    }

    public function testPersistConnect2() {
        $m1 = new Mongo("localhost:27017", array("persist" => ""));
        $m2 = new Mongo("localhost:27017", array("persist" => ""));

        // make sure this doesn't disconnect $m2
        unset($m1);

        $c = $m2->selectCollection("phpunit","bar");
        $c->setSlaveOkay(true);
        $c->findOne();
    }
/*
    public function test__toString() {
        $this->assertEquals("[localhost:27017]", $this->object->__toString());
        $this->object->connect();
        $this->assertEquals("localhost:27017", $this->object->__toString());

        $m = new Mongo();
        $this->assertEquals("localhost:27017", $m->__toString());
    }

    public function test__toString2() {
        $m = new Mongo("mongodb://localhost:27018,localhost:27017,localhost:27019");
        $this->assertEquals("[localhost:27018],localhost:27017,[localhost:27019]", $m->__toString());
        $m->phpunit->bar->findOne();
        $this->assertEquals("[localhost:27018],localhost:27017,[localhost:27019]", $m->__toString());
        $this->assertEquals(51, strlen($m->__toString()));

        // realloc
        $m = new Mongo("mongodb://localhostalocalhostalocalhostalocalhostalocalhostalocalhostalocalhostalocalhostalocalhostalocalhostalocalhostalocalhostalocalhostalocalhostalocalhostalocalhostalocalhostalocalhostalocalhostalocalhostalocalhostalocalhostalocalhostalocalhostalocalhosta:27018,localhost:27017");
        $m->phpunit->c->findOne();
        $this->assertEquals("[localhostalocalhostalocalhostalocalhostalocalhostalocalhostalocalhostalocalhostalocalhostalocalhostalocalhostalocalhostalocalhostalocalhostalocalhostalocalhostalocalhostalocalhostalocalhostalocalhostalocalhostalocalhostalocalhostalocalhostalocalhosta:27018],localhost:27017", $m->__toString());
        $this->assertEquals(274, strlen($m->__toString()));
    }
*/
    /**
     * @expectedException Exception
     */
    public function testSelectDBException1()
    {
        $db = $this->object->selectDB("");
    }

    /**
     * @expectedException Exception
     */
    public function testSelectDBException2()
    {
        $db = $this->object->selectDB("my database");
    }

    /**
     * @expectedException Exception
     */
    public function testSelectDBException3()
    {
        $db = $this->object->selectDB("x.y.z");
    }

    /**
     * @expectedException Exception
     */
    public function testSelectDBException4()
    {
        $db = $this->object->selectDB(".");
    }

    /**
     * @expectedException Exception
     */
    public function testSelectDBException5()
    {
        $db = $this->object->selectDB(null);
    }

    public function testSelectDB() {
        if (preg_match("/5\.1\../", phpversion())) {
            $this->markTestSkipped("No implicit __toString in 5.1");
            return;
        }

        $db = $this->object->selectDB("phpunit");
        $this->assertEquals((string)$db, "phpunit");
        $db = $this->object->selectDB("line\nline");
        $this->assertEquals((string)$db, "line\nline");
        $db = $this->object->selectDB("[x,y]");
        $this->assertEquals((string)$db, "[x,y]");
        $db = $this->object->selectDB(4);
        $this->assertEquals((string)$db, "4");
    }

    /**
     * @expectedException Exception
     */
    public function testSelectCollectionException1()
    {
        $db = $this->object->selectCollection("", "xyz");
    }

    public function testSelectCollection() {
        if (preg_match("/5\.1\../", phpversion())) {
            $this->markTestSkipped("No implicit __toString in 5.1");
            return;
        }

        $c = $this->object->selectCollection("phpunit", "bar.baz");
        $this->assertEquals((string)$c, "phpunit.bar.baz");
        $c = $this->object->selectCollection("1", "6");
        $this->assertEquals((string)$c, "1.6");
        $c = $this->object->selectCollection("phpunit", '$cmd');
        $this->assertEquals((string)$c, 'phpunit.$cmd');
    }

    public function testDropDB() {
        $this->object->connect();
        $c = $this->object->selectCollection("temp", "foo");

        $result = $c->db->command(array("ismaster" => 1));
        if (!$result['ismaster']) {
            $this->markTestSkipped("can't test writes on slave");
            return;
        }
        $c->insert(array('x' => 1));

        $this->object->dropDB("temp");
        $this->assertEquals($c->findOne(), NULL);

        $db = $this->object->selectDB("temp");
        $c->insert(array('x' => 1));

        $this->object->dropDB($db);
        $this->assertEquals($c->findOne(), NULL);
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testLastError() {
        $m = new Mongo();
        $m->resetError();
        $err = $m->lastError();
        $this->assertEquals(null, $err['err'], json_encode($err));
        $this->assertEquals(0, $err['n'], json_encode($err));
        $this->assertEquals(true, (bool)$err['ok'], json_encode($err));

        $m->forceError();
        $err = $m->lastError();
        $this->assertNotNull($err['err']);
        $this->assertEquals($err['n'], 0);
        $this->assertEquals((bool)$err['ok'], true);
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testPrevError() {
        $m = new Mongo();
        $m->resetError();
        $err = $m->prevError();
        $this->assertEquals($err['err'], null);
        $this->assertEquals($err['n'], 0);
        $this->assertEquals($err['nPrev'], -1);
        $this->assertEquals((bool)$err['ok'], true);

        $m->forceError();
        $err = $m->prevError();
        $this->assertNotNull($err['err']);
        $this->assertEquals($err['n'], 0);
        $this->assertEquals($err['nPrev'], 1);
        $this->assertEquals((bool)$err['ok'], true);
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testResetError() {
        $m = new Mongo();
        $m->resetError();
        $err = $m->lastError();
        $this->assertEquals($err['err'], null);
        $this->assertEquals($err['n'], 0);
        $this->assertEquals((bool)$err['ok'], true);
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testForceError() {
        $m = new Mongo();
        $m->forceError();
        $err = $m->lastError();
        $this->assertNotNull($err['err']);
        $this->assertEquals($err['n'], 0);
        $this->assertEquals((bool)$err['ok'], true);
    }

    public function testClose() {
        $this->object = new Mongo();
        $this->assertTrue($this->object->connected);

        $this->object->close();
        $this->assertFalse($this->object->connected);

        $this->object->close();
        $this->assertFalse($this->object->connected);
    }

    public function testMongoFormat() {
      $m = new Mongo("mongodb://localhost");
      $m = new Mongo("mongodb://localhost:27017");
      $m = new Mongo("mongodb://localhost:27017,localhost:27018");
      $m = new Mongo("mongodb://localhost:27017,localhost:27018,localhost:27019");
      $m = new Mongo("mongodb://localhost:27018,localhost,localhost:27019");
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testPersistConn() {
      $m1 = new Mongo("localhost", array("persist" => ""));

      // uses the same connection as $m1
      $m2 = new Mongo("localhost", array("persist" => ""));
      $m2->persistConnect();

      // creates a new connection
      $m3 = new Mongo("127.0.0.1", array("persist" => ""));
      $m3->persistConnect();

      // creates a new connection
      $m4 = new Mongo("127.0.0.1:27017", array("persist" => ""));
      $m4->persistConnect();

      // creates a new connection
      $m5 = new Mongo("localhost", array("persist" => ""));
      $m5->persistConnect("foo");

      // uses the $m5 connection
      $m6 = new Mongo("localhost", array("persist" => ""));
      $m6->persistConnect("foo");

      // uses $md5
      $m7 = new Mongo("localhost", array("persist" => ""));
      $m7->persistConnect("foo", "bar");

      $m8 = new Mongo();
    }

    public function testPersistConn2() {
      $m1 = new Mongo("localhost", array("persist" => ""));

      // uses the same connection as $m1
      $m2 = new Mongo("localhost", array("persist" => ""));

      // creates a new connection
      $m3 = new Mongo("127.0.0.1", array("persist" => ""));

      // creates a new connection
      $m4 = new Mongo("127.0.0.1:27017", array("persist" => ""));

      // creates a new connection
      $m5 = new Mongo("localhost", array("persist" => "foo"));

      // uses the $m5 connection
      $m6 = new Mongo("localhost", array("persist" => "foo"));

      $m8 = new Mongo();
    }
/*
    public function testAuthenticate1() {
      exec("mongo tests/addUser.js", $output, $exit_code);
      if ($exit_code == 0) {
        $m = new Mongo("mongodb://testUser:testPass@localhost");
      }
    }

    public function testAuthenticate2() {
      exec("mongo tests/addUser.js", $output, $exit_code);
      if ($exit_code != 0) {
        $this->markTestSkipped("can't add user");
        return;
      }
      $ok = true;

      try {
        $m = new Mongo("mongodb://testUser:testPa@localhost");
      }
      catch(MongoConnectionException $e) {
        $ok = false;
      }

      $this->assertFalse($ok);
    }
*/
    public function testGetters() {
        if (preg_match("/5\.1\../", phpversion())) {
            $this->markTestSkipped("No implicit __toString in 5.1");
            return;
        }

        $m = new Mongo();
        $db = $m->phpunit;
        $this->assertTrue($db instanceof MongoDB);
        $this->assertEquals("$db", "phpunit");

        $c = $db->bar;
        $this->assertTrue($c instanceof MongoCollection);
        $this->assertEquals("$c", "phpunit.bar");

        $c2 = $c->baz;
        $this->assertTrue($c2 instanceof MongoCollection);
        $this->assertEquals("$c2", "phpunit.bar.baz");

        $x = $m->phpunit->bar->baz;
        $this->assertTrue($x instanceof MongoCollection);
        $this->assertEquals("$x", "phpunit.bar.baz");
    }


    public function testStatic() {
        $start = memory_get_usage(true);

        for ($i=0; $i<100; $i++) {
          StaticFunctionTest::connect();
        }
        $this->assertEquals($start, memory_get_usage(true));
    }


    public function testListDBs() {
        $m = new Mongo();
        $dbs = $m->listDBs();
        $this->assertEquals(true, (bool)$dbs['ok'], json_encode($dbs));
        $this->assertTrue(array_key_exists('databases', $dbs));
    }

    /*
     * our current test framework can't really test this, so this just passes
     * a couple options and checks things don't explode.
     */
    public function testTimeout() {
      $m = new Mongo("localhost", array("timeout" => 0));
      $m = new Mongo("localhost", array("timeout" => 200000));
      $m = new Mongo("localhost", array("timeout" => -2));
      $m = new Mongo("localhost", array("timeout" => "foo"));
      $m = new Mongo("localhost", array("timeout" => array("x" => 1)));

      $db = $m->phpunit;
      $result = $db->command(array("ismaster" => 1));
      if (!$result['ismaster']) {
        $this->markTestSkipped("can't test writes on slave");
        return;
      }

      $c = $db->c;
      $c->drop();
      $c->insert(array("x" => 1), array("safe"=>true));
      $obj = $c->findOne();
      $this->assertEquals(1, $obj['x'], json_encode($c));
    }

    /*
     * again, not really testing functionality.
     */
	/*
    public function testDB() {
      $m = new Mongo("localhost/phpunit");
      $m = new Mongo("localhost/bar/baz");
      $m = new Mongo("localhost/");
    }
*/
    /*
     * test with ports
     */
	/*
    public function testDBPorts() {
      $m = new Mongo("localhost:27017/phpunit");
      $m = new Mongo("localhost:27017/bar/baz");
      $m = new Mongo("localhost:27017/");
      $m = new Mongo("localhost:27017,localhost:27019/");
    }
	*/

    /*
     * regression
     */
    public function testGetter() {
      if (preg_match("/5\.1\../", phpversion())) {
        $this->markTestSkipped("No implicit __toString in 5.1");
        return;
      }

      $db = $this->object->selectDB('db');
      $this->assertEquals('db', $db->__toString());
      $db = $this->object->selectDB($db);
      $this->assertEquals('db', $db->__toString());
    }

    public function testGetter2() {
      if (preg_match("/5\.1\../", phpversion())) {
        $this->markTestSkipped("No implicit __toString in 5.1");
        return;
      }

      $db = $this->object->__get('db');
      $this->assertEquals('db', $db->__toString());
      $db = $this->object->__get($db);
      $this->assertEquals('db', $db->__toString());
    }

    public function testDomainSock() {
        $os = php_uname("s");
        if (preg_match("/win/i", $os)) {
            $this->markTestSkipped("no domain sockets on windows");
            return;
        }

        try {
            $conn = new Mongo("mongodb:///tmp/mongodb-27017.sock");
            $this->assertEquals(true, $conn->connected);

            $conn = new Mongo("mongodb:///tmp/mongodb-27017.sock:0/phpunit");
            $this->assertEquals(true, $conn->connected);
        }
        catch (MongoConnectionException $e) {
            $this->markTestSkipped("connecting to domain sockets failed: ".$e->getMessage());
        }
    }

    /**
     * @expectedException MongoConnectionException
     */
    public function testDomainSock2() {
        $conn = new Mongo("mongodb:///tmp/phpunit");
    }

    public function testSlaveOkay1() {
        $conn = new Mongo("mongodb://localhost", array("replicaSet" => true, "slaveOkay" => true));
    }

    public function testPersistStatus() {
        $conn = new Mongo("mongodb://localhost", array("persist" => "chkPS"));
        //        $this->assertEquals($conn->status, "new");
        $conn2 = new Mongo("mongodb://localhost", array("persist" => "chkPS"));
        //        $this->assertEquals($conn2->status, "recycled");
    }

    public function testSlaveOkay() {
        $conn = new Mongo("mongodb://localhost", array("replicaSet" => true, "slaveOkay" => true));
        $this->assertTrue($conn->getSlaveOkay());
        $db = $conn->somedb;
        $this->assertTrue($db->getSlaveOkay());
        $c = $db->somec;
        $this->assertTrue($c->getSlaveOkay());

        $conn->setSlaveOkay(false);
        $this->assertFalse($conn->getSlaveOkay());
        $this->assertTrue($db->getSlaveOkay());
        $this->assertTrue($c->getSlaveOkay());

        $db = $conn->somedb;
        $this->assertFalse($db->getSlaveOkay());
        $c = $db->somec;
        $this->assertFalse($c->getSlaveOkay());

        $db->setSlaveOkay(true);
        $this->assertTrue($db->getSlaveOkay());

        $c->setSlaveOkay(true);
        $this->assertTrue($c->getSlaveOkay());

        $conn->setSlaveOkay(true);
        $this->assertTrue($conn->getSlaveOkay());
    }

    public function testPoolConnect() {
        $conn = new Mongo();

        $pool1 = Mongo::poolDebug();

        $orig = null;
        foreach ($pool1 as $host => $info) {
            if (strpos($host, 'localhost:27017...') === 0) {
                $orig = $info;
            }
        }

        $conn->connect();
        $conn->connect();
        $conn->connect();

        $pool2 = Mongo::poolDebug();

        $followup = null;
        foreach ($pool2 as $host => $info) {
            if (strpos($host, 'localhost:27017...') === 0) {
                $followup = $info;
            }
        }
        $this->assertEquals($orig['in use'], $followup['in use']);
    }

    public function testPoolConnect1() {
        $conn = new Mongo();

        $pool1 = MongoPool::info();

        $orig = null;
        foreach ($pool1 as $host => $info) {
            if (strpos($host, 'localhost:27017...') === 0) {
                $orig = $info;
            }
        }

        $conn->connect();
        $conn->connect();
        $conn->connect();

        $pool2 = MongoPool::info();

        $followup = null;
        foreach ($pool2 as $host => $info) {
            if (strpos($host, 'localhost:27017...') === 0) {
                $followup = $info;
            }
        }

        $this->assertEquals($orig['in use'], $followup['in use']);
    }

    public function testPoolSize() {
        $this->assertEquals(Mongo::getPoolSize(), -1);
        Mongo::setPoolSize(4.1);
        $this->assertEquals(Mongo::getPoolSize(), 4);
        Mongo::setPoolSize(0);

        $thrown = false;
        try {
            $m = new Mongo("mongodb://localhost:20000");
        }
        catch (MongoException $e) {
            $this->assertStringEndsWith("pool", $e->getMessage());
            $thrown = true;
        }
        $this->assertTrue($thrown);

        Mongo::setPoolSize(-1);
    }

    public function testPoolSize2() {
        $this->assertEquals(MongoPool::getSize(), -1);
        MongoPool::setSize(4.1);
        $this->assertEquals(MongoPool::getSize(), 4);
        MongoPool::setSize(0);

        $thrown = false;
        try {
            $m = new Mongo("mongodb://localhost:20000");
        }
        catch (MongoException $e) {
            $this->assertStringEndsWith("pool", $e->getMessage());
            $thrown = true;
        }
        $this->assertTrue($thrown);

        MongoPool::setSize(-1);
    }

    // make sure connection still works after forking
    public function testFork() {
        if (!extension_loaded("pcntl")) {
            $this->markTestSkipped("No pcntl");
            return;
        }

        $forks = 7;

        $m = new Mongo();
        $parent = $m->log->c;

        for ($i=0; $i<1000; $i++) {
            $parent->insert(array("DONE" => 0), array("safe" => true));
        }

        for($i = 1;$i <= $forks;$i++){
            $pid = "pid".$i;

            ${$pid} = pcntl_fork();
            if(${$pid} == -1) {
                // Something went wrong (handle errors here)
                die("Could not fork!");
            }
            elseif(${$pid} == 0) {
                // The child

                $conn = new Mongo();
                $child = $conn->log->c;

                $get = $child->find(array("DONE"=>0))->limit(10);
                foreach ($get as $row) {
                    $child->update(array("_id" => $row['_id']), array('$set' => array('DONE' => 1)));
                }

                exit(); // The child dies, becoming a zombie
            }
            else {
                // This part is only executed in the parent
                // Push the PID of the created child into $children
                $children[] = ${$pid};
            }
        }

        // Clean up after the kids!
        while(count($children) > 0){
            $myId = pcntl_waitpid(-1, $status, WNOHANG);
            foreach($children as $key => $pid){
                if($myId == $pid) unset($children[$key]);
            }
            usleep(100);
        }

        // Make sure parent works
        $done = $parent->find(array("DONE"=>1))->count();
        $notDone = $parent->find(array("DONE"=>0))->count();

        $this->assertGreaterThan(0, $done);
        $this->assertGreaterThan(0, $notDone);
    }
}

class StaticFunctionTest {
  private static $conn = null;

  public static function connect()
  {
    self::$conn = new Mongo;
  }
}

?>