/**
  * Convert a comparison expression into the target query language output
  *
  * @param \Doctrine\Common\Collections\Expr\Comparison $comparison
  *
  * @return mixed
  */
 public function walkComparison(Comparison $comparison)
 {
     $field = $comparison->getField();
     $value = $comparison->getValue()->getValue();
     // shortcut for walkValue()
     return $this->persister->getSelectConditionStatementSQL($field, $value, null, $comparison->getOperator());
 }
 public function testRetrieveUserTracker()
 {
     $user = new User();
     $tracker = $this->tracker();
     $this->em->expects($this->once())->method('getUnitOfWork')->will($this->returnValue($this->unitOfWork));
     $this->unitOfWork->expects($this->once())->method('getEntityPersister')->with(self::CLASS_NAME)->will($this->returnValue($this->entityPersister));
     $this->entityPersister->expects($this->once())->method('load')->with(['user' => $user], null, null, [], 0, 1, null)->will($this->returnValue($tracker));
     $this->repository->retrieveUserTracker($user);
 }
Beispiel #3
0
 /**
  * Converts a comparison expression into the target query language output.
  *
  * @param \Doctrine\Common\Collections\Expr\Comparison $comparison
  *
  * @return mixed
  */
 public function walkComparison(Comparison $comparison)
 {
     $field = $comparison->getField();
     $value = $comparison->getValue()->getValue();
     // shortcut for walkValue()
     if (isset($this->classMetadata->associationMappings[$field]) && $value !== null && !is_object($value) && !in_array($comparison->getOperator(), array(Comparison::IN, Comparison::NIN))) {
         throw PersisterException::matchingAssocationFieldRequiresObject($this->classMetadata->name, $field);
     }
     return $this->persister->getSelectConditionStatementSQL($field, $value, null, $comparison->getOperator());
 }
 public function testFindAllByTicket()
 {
     $messageReference = $this->getMessageReference();
     $ticket = $messageReference->getTicket();
     $references = array($messageReference);
     $this->em->expects($this->once())->method('getUnitOfWork')->will($this->returnValue($this->unitOfWork));
     $this->unitOfWork->expects($this->once())->method('getEntityPersister')->with($this->equalTo(self::DUMMY_CLASS_NAME))->will($this->returnValue($this->entityPersister));
     $this->entityPersister->expects($this->once())->method('loadAll')->with($this->equalTo(array('ticket' => $ticket)), null, null, null)->will($this->returnValue($references));
     $result = $this->repository->findAllByTicket($ticket);
     $this->assertEquals($references, $result);
 }
 /**
  * @test
  */
 public function thatBranchEmailConfigurationRetrievesByBranchId()
 {
     $branchId = 1;
     $branchEmailConfiguration = $this->getBranchEmailConfiguartion();
     $this->em->expects($this->once())->method('getUnitOfWork')->will($this->returnValue($this->unitOfWork));
     $this->unitOfWork->expects($this->once())->method('getEntityPersister')->with($this->equalTo(self::DUMMY_CLASS_NAME))->will($this->returnValue($this->entityPersister));
     $this->entityPersister->expects($this->once())->method('load')->with($this->equalTo(array('branchId' => $branchId)), $this->equalTo(null), $this->equalTo(null), array(), $this->equalTo(0), $this->equalTo(1), $this->equalTo(null))->will($this->returnValue($branchEmailConfiguration));
     $retrievedBranchEmailConfiguration = $this->repository->findOneBy(array('branchId' => $branchId));
     $this->assertNotNull($retrievedBranchEmailConfiguration);
     $this->assertEquals($branchEmailConfiguration, $retrievedBranchEmailConfiguration);
 }
 protected function expectBasicLoad($entity, $id, $lockMode = LockMode::NONE, $lockVersion = null)
 {
     if (Version::compare('2.2.0') === -1) {
         $this->em->expects($this->once())->method('find')->with(get_class($this->entity), $id, $lockMode, $lockVersion)->will($this->returnValue($entity));
     } else {
         $this->persister->expects($this->once())->method('load')->with(array('id' => $id))->will($this->returnValue($entity));
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function _prepareInsertData($entity)
 {
     $data = parent::_prepareInsertData($entity);
     // Populate the discriminator column
     $discColumn = $this->_class->discriminatorColumn;
     $this->_columnTypes[$discColumn['name']] = $discColumn['type'];
     $data[$this->_getDiscriminatorColumnTableName()][$discColumn['name']] = $this->_class->discriminatorValue;
     return $data;
 }
 /**
  * @test
  */
 public function thatGetsAll()
 {
     $entities = array(new EntityStub(), new EntityStub());
     $this->em->expects($this->once())->method('getUnitOfWork')->will($this->returnValue($this->unitOfWork));
     $this->unitOfWork->expects($this->once())->method('getEntityPersister')->with($this->equalTo(self::CLASS_NAME))->will($this->returnValue($this->entityPersister));
     $this->entityPersister->expects($this->once())->method('loadAll')->with($this->equalTo(array()), $this->equalTo(null), $this->equalTo(null), $this->equalTo(null))->will($this->returnValue($entities));
     $retrievedEntities = $this->repository->getAll();
     $this->assertEquals($entities, $retrievedEntities);
 }
 public function testListAllByUserAndPeriod()
 {
     $user = new User();
     $period = new Period(new \DateTime('2014-12-01'), new \DateTime('2014-12-31'));
     $worklogs = [$this->worklog()];
     $this->em->expects($this->once())->method('getUnitOfWork')->will($this->returnValue($this->unitOfWork));
     $this->unitOfWork->expects($this->once())->method('getEntityPersister')->with(self::CLASS_NAME)->will($this->returnValue($this->entityPersister));
     $this->entityPersister->expects($this->once())->method('loadCriteria')->with($this->logicalAnd($this->isInstanceOf('\\Doctrine\\Common\\Collections\\Criteria')))->will($this->returnValue($worklogs));
     $result = $this->repository->listAllByUserAndPeriod($user, $period);
     $this->assertInstanceOf('\\Doctrine\\Common\\Collections\\ArrayCollection', $result);
     $this->assertEquals($result->toArray(), $worklogs);
 }
Beispiel #10
0
 /**
  * Creates a closure capable of finalizing state a cloned proxy
  *
  * @param \Doctrine\Common\Persistence\Mapping\ClassMetadata $classMetadata
  * @param \Doctrine\ORM\Persisters\BasicEntityPersister      $entityPersister
  *
  * @return \Closure
  *
  * @throws \Doctrine\ORM\EntityNotFoundException
  */
 private function createCloner(ClassMetadata $classMetadata, BasicEntityPersister $entityPersister)
 {
     return function (BaseProxy $proxy) use($entityPersister, $classMetadata) {
         if ($proxy->__isInitialized()) {
             return;
         }
         $proxy->__setInitialized(true);
         $proxy->__setInitializer(null);
         $class = $entityPersister->getClassMetadata();
         $original = $entityPersister->load($classMetadata->getIdentifierValues($proxy));
         if (null === $original) {
             throw new EntityNotFoundException();
         }
         foreach ($class->getReflectionClass()->getProperties() as $reflectionProperty) {
             $propertyName = $reflectionProperty->getName();
             if ($class->hasField($propertyName) || $class->hasAssociation($propertyName)) {
                 $reflectionProperty->setAccessible(true);
                 $reflectionProperty->setValue($proxy, $reflectionProperty->getValue($original));
             }
         }
     };
 }
 /**
  * {@inheritDoc}
  */
 protected function doInitialize()
 {
     $elements = $this->entityPersister->loadCriteria($this->criteria);
     $this->collection = new ArrayCollection($elements);
 }