/**
  * @param string $search
  * @param int $page
  * @param int $perPage
  * @param array $foundElements
  * @param array $resultData
  * @param array $expectedIds
  * @return \PHPUnit_Framework_MockObject_MockObject
  */
 protected function assertSearchCall($search, $page, $perPage, array $foundElements, array $resultData, array $expectedIds)
 {
     $searchResult = $this->getMockBuilder('Oro\\Bundle\\SearchBundle\\Query\\Result')->disableOriginalConstructor()->getMock();
     $searchResult->expects($this->once())->method('getElements')->will($this->returnValue($foundElements));
     $this->indexer->expects($this->once())->method('simpleSearch')->with($search, $page - 1, $perPage + 1, 'alias')->will($this->returnValue($searchResult));
     $queryBuilder = $this->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->getMock();
     $query = $this->getMockBuilder('Doctrine\\ORM\\AbstractQuery')->disableOriginalConstructor()->setMethods(['getResult'])->getMockForAbstractClass();
     $query->expects($this->once())->method('getResult')->will($this->returnValue($resultData));
     $expr = $this->getMockBuilder('Doctrine\\ORM\\Query\\Expr')->disableOriginalConstructor()->getMock();
     $expr->expects($this->once())->method('in')->with('e.id', $expectedIds)->will($this->returnSelf());
     $queryBuilder->expects($this->once())->method('expr')->will($this->returnValue($expr));
     $queryBuilder->expects($this->once())->method('where')->with($expr)->will($this->returnSelf());
     $this->aclHelper->expects($this->once())->method('apply')->with($queryBuilder, 'VIEW')->will($this->returnValue($query));
     $this->entityRepository->expects($this->any())->method('createQueryBuilder')->will($this->returnValue($queryBuilder));
     return $searchResult;
 }
 /**
  * @param string $search
  * @param int $page
  * @param int $perPage
  * @param array $foundElements
  * @param array $resultData
  * @param array $expectedIds
  * @return \PHPUnit_Framework_MockObject_MockObject
  */
 protected function assertSearchCall($search, $page, $perPage, array $foundElements, array $resultData, array $expectedIds)
 {
     /* @var $searchResult Result|\PHPUnit_Framework_MockObject_MockObject */
     $searchResult = $this->getMockBuilder('Oro\\Bundle\\SearchBundle\\Query\\Result')->disableOriginalConstructor()->getMock();
     $searchResult->expects($this->once())->method('getElements')->willReturn($foundElements);
     $this->indexer->expects($this->once())->method('simpleSearch')->with($search, $page - 1, $perPage + 1, 'alias')->willReturn($searchResult);
     /* @var $queryBuilder QueryBuilder|\PHPUnit_Framework_MockObject_MockObject */
     $queryBuilder = $this->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->getMock();
     /* @var $query AbstractQuery|\PHPUnit_Framework_MockObject_MockObject */
     $query = $this->getMockBuilder('Doctrine\\ORM\\AbstractQuery')->disableOriginalConstructor()->setMethods(['getResult'])->getMockForAbstractClass();
     $query->expects($this->once())->method('getResult')->willReturn($resultData);
     /* @var $expr Expr|\PHPUnit_Framework_MockObject_MockObject */
     $expr = $this->getMockBuilder('Doctrine\\ORM\\Query\\Expr')->disableOriginalConstructor()->getMock();
     $expr->expects($this->once())->method('in')->with('e.id', $expectedIds)->will($this->returnSelf());
     $expr->expects($this->once())->method('asc')->with('e.email')->will($this->returnSelf());
     $queryBuilder->expects($this->exactly(2))->method('expr')->willReturn($expr);
     $queryBuilder->expects($this->once())->method('where')->with($expr)->will($this->returnSelf());
     $queryBuilder->expects($this->once())->method('addOrderBy')->with($expr)->will($this->returnSelf());
     $queryBuilder->expects($this->any())->method('andWhere')->with('e.account = :account')->will($this->returnSelf());
     $this->aclHelper->expects($this->once())->method('apply')->with($queryBuilder, 'VIEW')->willReturn($query);
     $this->entityRepository->expects($this->any())->method('createQueryBuilder')->willReturn($queryBuilder);
     return $searchResult;
 }