/**
  * Sets up this test case
  *
  */
 public function setUp()
 {
     $this->persistenceManager = $this->getMockBuilder(PersistenceManager::class)->disableOriginalConstructor()->getMock();
     $this->persistenceManager->expects($this->any())->method('getObjectDataByQuery')->will($this->returnValue(['one', 'two']));
     $this->dataMapper = $this->createMock(DataMapper::class);
     $this->query = $this->createMock(QueryInterface::class);
     $this->queryResult = new QueryResult($this->query);
     $this->queryResult->injectPersistenceManager($this->persistenceManager);
     $this->queryResult->injectDataMapper($this->dataMapper);
     $this->sampleResult = [['foo' => 'Foo1', 'bar' => 'Bar1'], ['foo' => 'Foo2', 'bar' => 'Bar2']];
     $this->dataMapper->expects($this->any())->method('mapToObjects')->will($this->returnValue($this->sampleResult));
 }
 /**
  * Returns the first object in the result set, if any.
  *
  * @return mixed The first object of the result set or NULL if the result set was empty
  * @api
  */
 public function getFirst()
 {
     if (is_array($this->queryResult)) {
         $queryResult =& $this->queryResult;
     } else {
         $query = clone $this->query;
         $query->setLimit(1);
         $queryResult = $this->dataMapper->mapToObjects($this->persistenceManager->getObjectDataByQuery($query));
     }
     return isset($queryResult[0]) ? $queryResult[0] : null;
 }
Example #3
0
 /**
  * Returns the object with the (internal) identifier, if it is known to the
  * backend. Otherwise NULL is returned.
  *
  * @param mixed $identifier
  * @param string $objectType
  * @param boolean $useLazyLoading This option is ignored in this persistence manager
  * @return object The object for the identifier if it is known, or NULL
  * @api
  */
 public function getObjectByIdentifier($identifier, $objectType = null, $useLazyLoading = false)
 {
     if (isset($this->newObjects[$identifier])) {
         return $this->newObjects[$identifier];
     }
     if ($this->persistenceSession->hasIdentifier($identifier)) {
         return $this->persistenceSession->getObjectByIdentifier($identifier);
     } else {
         $objectData = $this->backend->getObjectDataByIdentifier($identifier, $objectType);
         if ($objectData !== false) {
             return $this->dataMapper->mapToObject($objectData);
         } else {
             return null;
         }
     }
 }