Example #1
0
 public function testIfWillStoreNonEmptyPassword()
 {
     $model = new ModelWithSecretField();
     $em = new EntityManager($model);
     $finder = new Finder($model);
     $model->password = '******';
     $em->update();
     $found = $finder->find();
     $this->assertSame(1, $finder->count(), 'That only one document is in collection');
     $this->assertSame('foo', $found->password, 'That non empty password was saved');
     $found->password = '';
     $em = new EntityManager($found);
     $em->update();
     $found2 = $finder->find();
     $this->assertSame(1, $finder->count(), 'That only one document is in collection');
     $this->assertSame('foo', $found2->password, 'That empty password was NOT saved');
 }
Example #2
0
 public function testIfWillUpdateByModifyDocument()
 {
     $model = new ModelWithI18N();
     $model->_id = new \MongoId();
     $model->active = true;
     $model->title = 'foo';
     $em = new EntityManager($model);
     $finder = new Finder($model);
     $em->save();
     $found = $finder->findByPk($model->_id);
     $this->assertSame($model->title, $found->title);
     $this->assertSame($model->active, $found->active);
     $em = new EntityManager($found);
     $found->title = 'bar';
     // This attribute should be ignored
     $found->active = false;
     $em->update(['title'], true);
     $updated = $finder->findByPk($model->_id);
     $this->assertSame($found->title, $updated->title);
     $this->assertSame($model->active, $updated->active);
 }
Example #3
0
 /**
  * Move to a new parent
  * @param string|MongoId $parentId
  * @param string[]|MongoId[] $order
  * @Ignored
  */
 public function moveTo($parentId, $order = [])
 {
     $this->parentId = $parentId;
     (new EntityManager($this))->update(['parentId']);
     $i = 0;
     $node = new static();
     $em = new EntityManager($node);
     foreach ((array) $order as $id) {
         $node->_id = $id;
         $node->order = $i++;
         $em->update(['order']);
     }
 }