예제 #1
0
 function testScalarToArray()
 {
     $c = new Model1();
     $c->a = 1;
     $c->save();
     $c->a = array(1, 2);
     $c->save();
     $c->a[0] = array(1, 2);
     $c->a[1] = 3;
     $c->save();
     $id = $c->getID();
     $c->reset();
     $c->where('_id', $id);
     $c->doQuery();
     $this->assertEquals(array(array(1, 2), 3), $c->a);
 }
예제 #2
0
 public function testValidatesPresence()
 {
     try {
         $c = new Model1();
         $c->b = 'cesar';
         $c->save();
         $this->assertTrue(FALSE);
     } catch (ActiveMongo_FilterException $e) {
         $this->assertTrue(TRUE);
     }
 }
예제 #3
0
 function testFindAndReferences()
 {
     $c = new Model1();
     $c->a = 5;
     $c->save();
     $d = new Model1();
     $d->a = 9;
     $d->ref = $c;
     $d->save();
     $e = new Model1();
     $e->ref = $c;
     foreach ($e->find() as $r) {
         $this->assertTrue(MongoDBREf::isRef($r->ref));
         $r->doDeferencing();
         $this->assertEquals($r->ref->a, $c->a);
         $this->assertEquals($d->a, $r->a);
     }
 }
예제 #4
0
 function testBeforeDelete()
 {
     Model1::addEvent('before_delete', array($this, 'on_delete'));
     $m1 = new Model1();
     $m1->a = rand();
     $m1->save();
     $id = (string) $m1->getId();
     $m1->delete();
     $this->assertEquals($id, $this->deleted);
 }
예제 #5
0
 function testFindWithSingleID()
 {
     $d = new Model1();
     $d->a = 5;
     $d->save();
     $c = new Model1();
     $c->find($d->getID());
     $this->assertEquals(1, $c->count());
     $this->assertEquals($c->a, $d->a);
 }