Esempio n. 1
0
 public function testShouldCreateMongoDBRefFromCollectionAndStringId()
 {
     $parent = new Parental();
     $parent->name = 'Parent';
     $parent->save();
     $child = new Child();
     $child->name = 'Child';
     $child->parent = DbRef::create('Parental', (string) $parent->getId());
     $child->save();
     $this->assertEquals((string) $child->readRef('parent')->getId(), (string) $parent->getId());
 }
Esempio n. 2
0
 public function testShouldThrowExceptionForInvalidMongoDBRef()
 {
     $parent = new Parental();
     $parent->name = 'Parent';
     $parent->save();
     $child = new Child();
     $child->name = 'Child';
     $child->parent = DbRef::create($parent);
     $child->save();
     $exception = null;
     try {
         $child->readRef('name');
     } catch (\Exception $e) {
         $exception = $e;
     }
     $this->assertInstanceOf('\\Vegas\\Db\\Adapter\\Mongo\\Exception\\InvalidReferenceException', $exception);
     $exception = null;
     try {
         $child->readRef('fake.nested');
     } catch (\Exception $e) {
         $exception = $e;
     }
     $this->assertInstanceOf('\\Vegas\\Db\\Adapter\\Mongo\\Exception\\InvalidReferenceException', $exception);
 }