/**
  * @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]);
 }