/**
  * @test
  */
 public function thatFilters()
 {
     $a = new EntityStub();
     $b = new EntityStub();
     $a->name = "DUMMY_NAME";
     $a->id = 1;
     $b->name = "NOT_DUMMY_NAME";
     $b->id = 2;
     $entities = array($a, $b);
     $pagingConfig = new FilterPagingProperties();
     $conditions = array(array('name', 'eq', 'DUMMY_NAME'));
     $whereExpr = new \Doctrine\ORM\Query\Expr\Comparison('e.name', 'eq', "'DUMMY_NAME'");
     $this->em->expects($this->once())->method('createQueryBuilder')->will($this->returnValue($this->queryBuilder));
     $this->queryBuilder->expects($this->once())->method('select')->with($this->equalTo('e'))->will($this->returnValue($this->queryBuilder));
     $this->queryBuilder->expects($this->once())->method('from')->with($this->equalTo($this->classMetadata->name), $this->equalTo('e'))->will($this->returnValue($this->queryBuilder));
     $this->queryBuilder->expects($this->atLeastOnce())->method('andWhere')->with($this->equalTo($whereExpr))->will($this->returnValue($this->queryBuilder));
     $this->queryBuilder->expects($this->once())->method('addOrderBy')->with($this->equalTo('e.id'), $this->equalTo($pagingConfig->getOrder()))->will($this->returnValue($this->queryBuilder));
     $this->queryBuilder->expects($this->once())->method('setFirstResult')->with($this->equalTo(0))->will($this->returnValue($this->queryBuilder));
     $this->queryBuilder->expects($this->once())->method('setMaxResults')->with($this->equalTo($pagingConfig->getLimit()))->will($this->returnValue($this->queryBuilder));
     $this->queryBuilder->expects($this->once())->method('getQuery')->will($this->returnValue($this->filterQuery));
     $this->queryBuilder->expects($this->any())->method('expr')->will($this->returnValue($this->expressionBuilder));
     $this->em->expects($this->any())->method('getExpressionBuilder')->will($this->returnValue($this->expressionBuilder));
     $this->expressionBuilder->expects($this->atLeastOnce())->method('literal')->with($this->equalTo('DUMMY_NAME'))->will($this->returnValue("'DUMMY_NAME'"));
     $this->expressionBuilder->expects($this->atLeastOnce())->method('eq')->with($this->equalTo('e.name'), $this->equalTo("'DUMMY_NAME'"))->will($this->returnValue($whereExpr));
     $this->em->expects($this->atLeastOnce())->method('newHydrator')->with($this->equalTo(Query::HYDRATE_OBJECT))->will($this->returnValue($this->objectHydrator));
     $this->objectHydrator->expects($this->atLeastOnce())->method('hydrateAll')->will($this->returnValue(array($a)));
     $filteredEntities = $this->repository->filter($conditions, $pagingConfig);
     $this->assertNotNull($filteredEntities);
     $this->assertTrue(is_array($filteredEntities));
     $this->assertNotEmpty($filteredEntities);
     $this->assertEquals($a, $filteredEntities[0]);
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 protected function _hydrateAll()
 {
     $listener = $this->_hints[TranslationWalker::HINT_TRANSLATION_LISTENER];
     $listener->setSkipOnLoad(true);
     $result = parent::_hydrateAll();
     $listener->setSkipOnLoad(false);
     return $result;
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 protected function _hydrateRow(array $data, array &$cache, array &$result)
 {
     if (isset($this->_hints[TranslationWalker::HINT_TRANSLATION_FALLBACKS])) {
         foreach ($this->_hints[TranslationWalker::HINT_TRANSLATION_FALLBACKS] as $field => $alias) {
             if ($data[$field] && !$data[$alias]) {
                 $data[$alias] = $data[$field];
             }
             unset($data[$field]);
         }
     }
     return parent::_hydrateRow($data, $cache, $result);
 }
 /**
  * @test
  */
 public function testSearch()
 {
     $a = new EntityStub();
     $b = new EntityStub();
     $a->name = "DUMMY_NAME";
     $a->status = "new";
     $a->id = 1;
     $b->name = "NOT_DUMMY_NAME";
     $b->status = "closed";
     $b->id = 2;
     $entities = array($a, $b);
     $pagingConfig = new FilterPagingProperties();
     $querySearch = 'NAM';
     $conditions = array(array('status', 'eq', 'new'));
     $this->em->expects($this->once())->method('createQueryBuilder')->will($this->returnValue($this->queryBuilder));
     $this->queryBuilder->expects($this->once())->method('select')->with($this->equalTo('e'))->will($this->returnValue($this->queryBuilder));
     $this->queryBuilder->expects($this->once())->method('from')->with($this->equalTo($this->classMetadata->name), $this->equalTo('e'))->will($this->returnValue($this->queryBuilder));
     $whereExpr = new \Doctrine\ORM\Query\Expr\Comparison('e.status', 'eq', 'new');
     $likeExprSubject = new \Doctrine\ORM\Query\Expr\Comparison('e.subject', 'like', '%NAM%');
     $likeExprDescription = new \Doctrine\ORM\Query\Expr\Comparison('e.description', 'like', '%NAM%');
     $whereExprOrx = new \Doctrine\ORM\Query\Expr\Orx($likeExprSubject, $likeExprDescription);
     $this->queryBuilder->expects($this->atLeastOnce())->method('andWhere')->with($this->logicalOr($this->equalTo($whereExpr), $this->equalTo($whereExprOrx)))->will($this->returnValue($this->queryBuilder));
     $this->queryBuilder->expects($this->once())->method('addOrderBy')->with($this->equalTo('e.id'), $this->equalTo($pagingConfig->getOrder()))->will($this->returnValue($this->queryBuilder));
     $this->queryBuilder->expects($this->once())->method('setFirstResult')->with($this->equalTo(0))->will($this->returnValue($this->queryBuilder));
     $this->queryBuilder->expects($this->once())->method('setMaxResults')->with($this->equalTo($pagingConfig->getLimit()))->will($this->returnValue($this->queryBuilder));
     $this->queryBuilder->expects($this->once())->method('getQuery')->will($this->returnValue($this->searchQuery));
     $this->queryBuilder->expects($this->any())->method('expr')->will($this->returnValue($this->expressionBuilder));
     $this->em->expects($this->any())->method('getExpressionBuilder')->will($this->returnValue($this->expressionBuilder));
     $this->expressionBuilder->expects($this->atLeast(2))->method('literal')->with($this->logicalOr($this->equalTo('new'), $this->equalTo('%' . $querySearch . '%')))->will($this->returnCallback(array($this, 'literalCallback')));
     $this->expressionBuilder->expects($this->atLeastOnce())->method('eq')->with($this->equalTo('e.status'), $this->equalTo('new'))->will($this->returnValue($whereExpr));
     $this->expressionBuilder->expects($this->atLeastOnce())->method('Orx')->with($this->anything(), $this->anything())->will($this->returnValue($whereExprOrx));
     $this->em->expects($this->atLeastOnce())->method('newHydrator')->with($this->equalTo(Query::HYDRATE_OBJECT))->will($this->returnValue($this->objectHydrator));
     $this->objectHydrator->expects($this->atLeastOnce())->method('hydrateAll')->will($this->returnValue(array($a)));
     $searchedEntities = $this->repository->search($querySearch, $conditions, $pagingConfig);
     $this->assertNotNull($searchedEntities);
     $this->assertTrue(is_array($searchedEntities));
     $this->assertNotEmpty($searchedEntities);
     $this->assertEquals($a, $searchedEntities[0]);
 }
コード例 #5
0
 /**
  * {@inheritdoc}
  */
 protected function cleanup()
 {
     parent::cleanup();
     $listener = $this->getTranslatableListener();
     $listener->setSkipOnLoad($this->savedSkipOnLoad !== null ? $this->savedSkipOnLoad : false);
 }
コード例 #6
0
 public function onClear($eventArgs)
 {
     parent::onClear($eventArgs);
     $this->lastRowData = NULL;
 }
コード例 #7
-22
 /**
  * 2.2 version
  * {@inheritdoc}
  */
 protected function hydrateAllData()
 {
     $listener = $this->getTranslatableListener();
     $listener->setSkipOnLoad(true);
     $result = parent::hydrateAllData();
     $listener->setSkipOnLoad(false);
     return $result;
 }
コード例 #8
-33
 /**
  * Hydrates all rows from the current statement instance at once.
  *
  * @return Collection
  */
 protected function hydrateAllData()
 {
     return new Collection(parent::hydrateAllData());
 }