示例#1
0
 public function testReferencesUsesAllKeys()
 {
     $dm = $this->getMockBuilder('Doctrine\\ODM\\MongoDB\\DocumentManager')->disableOriginalConstructor()->getMock();
     $class = $this->getMockBuilder('Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata')->disableOriginalConstructor()->getMock();
     $dm->expects($this->once())->method('createDBRef')->will($this->returnValue(array('$ref' => 'coll', '$id' => '1234', '$db' => 'db')));
     $class->expects($this->once())->method('getFieldMapping')->will($this->returnValue(array()));
     $expr = new Expr($dm, '$');
     $expr->setClassMetadata($class);
     $expr->field('foo')->references(new \stdClass());
     $this->assertEquals(array('foo.$ref' => 'coll', 'foo.$id' => '1234', 'foo.$db' => 'db'), $expr->getQuery(), '->references() uses all keys if no targetDocument is set');
 }
示例#2
0
 /**
  * Create a new Expr instance that can be used as an expression with the Builder
  *
  * @return Expr $expr
  */
 public function expr()
 {
     $expr = new Expr($this->dm);
     $expr->setClassMetadata($this->class);
     return $expr;
 }
 /**
  * Find all common attribute ids with values from a list of product ids
  * Only exists for ODM repository
  *
  * @param array $productIds
  *
  * @return array
  */
 protected function findValuesCommonAttributeIds(array $productIds)
 {
     $collection = $this->dm->getDocumentCollection($this->documentName);
     $expr = new Expr($this->dm);
     $class = $this->dm->getClassMetadata($this->documentName);
     $expr->setClassMetadata($class);
     $expr->field('_id')->in($productIds);
     $pipeline = [['$match' => $expr->getQuery()], ['$unwind' => '$values'], ['$group' => ['_id' => ['id' => '$_id', 'family' => '$family'], 'attribute' => ['$addToSet' => '$values.attribute']]]];
     return $collection->aggregate($pipeline)->toArray();
 }
示例#4
0
 public function testReferencesUsesSomeKeys()
 {
     $dm = $this->createMock('Doctrine\\ODM\\MongoDB\\DocumentManager');
     $uw = $this->createMock('Doctrine\\ODM\\MongoDB\\UnitOfWork');
     $documentPersister = $this->createMock('Doctrine\\ODM\\MongoDB\\Persisters\\DocumentPersister');
     $class = $this->createMock('Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata');
     $expected = array('foo.$ref' => 'coll', 'foo.$id' => '1234');
     $dm->expects($this->once())->method('createDBRef')->will($this->returnValue(array('$ref' => 'coll', '$id' => '1234')));
     $dm->expects($this->once())->method('getUnitOfWork')->will($this->returnValue($uw));
     $uw->expects($this->once())->method('getDocumentPersister')->will($this->returnValue($documentPersister));
     $documentPersister->expects($this->once())->method('prepareQueryOrNewObj')->with($expected)->will($this->returnValue($expected));
     $class->expects($this->once())->method('getFieldMapping')->will($this->returnValue(array('storeAs' => ClassMetadataInfo::REFERENCE_STORE_AS_DB_REF)));
     $expr = new Expr($dm);
     $expr->setClassMetadata($class);
     $expr->field('foo')->references(new \stdClass());
     $this->assertEquals($expected, $expr->getQuery(), '->references() uses some keys if storeAs=dbRef is set');
 }