Пример #1
0
 public function testSearch()
 {
     $result = ['list' => ['foo', 'bar'], 'total' => 123];
     // exec query
     $select = $this->getMockBuilder('\\Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->getMock();
     $total = $this->getMockBuilder('\\Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->getMock();
     $select->expects($this->once())->method('getQuery')->will($this->returnValue($this->getQuery($result['list'])));
     $total->expects($this->once())->method('getQuery')->will($this->returnValue($this->getQuery($result['total'], true)));
     /* @var $entity \PHPUnit_Framework_MockObject_MockObject|Search */
     $entity = $this->getMock('\\AnimeDb\\Bundle\\CatalogBundle\\Entity\\Search');
     // build query selector
     $builder = $this->getMockBuilder('\\AnimeDb\\Bundle\\CatalogBundle\\Service\\Item\\Search\\Selector\\Builder')->disableOriginalConstructor()->getMock();
     $methods = ['addCountry', 'addDateAdd', 'addDateEnd', 'addDatePremiere', 'addGenres', 'addLabels', 'addName', 'addStorage', 'addStudio', 'addType'];
     foreach ($methods as $method) {
         $builder->expects($this->once())->method($method)->with($entity)->will($this->returnSelf());
     }
     $builder->expects($this->once())->method('sort')->with('my_column', 'my_direction')->will($this->returnSelf());
     $builder->expects($this->once())->method('limit')->with(111)->will($this->returnSelf());
     $builder->expects($this->once())->method('offset')->with(222)->will($this->returnSelf());
     $builder->expects($this->once())->method('getQuerySelect')->will($this->returnValue($select));
     $builder->expects($this->once())->method('getQueryTotal')->will($this->returnValue($total));
     $this->selector->expects($this->once())->method('create')->will($this->returnValue($builder));
     // TODO add mocks
     $this->assertEquals($result, $this->driver->search($entity, 111, 222, 'my_column', 'my_direction'));
 }
Пример #2
0
 /**
  * @param Search $entity
  * @param int $limit
  * @param int $offset
  * @param string $sort_column
  * @param string $sort_direction
  *
  * @return array {list:[],total:0}
  */
 public function search(Search $entity, $limit, $offset, $sort_column, $sort_direction)
 {
     $selector = $this->selector->create()->addCountry($entity)->addDateAdd($entity)->addDateEnd($entity)->addDatePremiere($entity)->addGenres($entity)->addLabels($entity)->addName($entity)->addStorage($entity)->addStudio($entity)->addType($entity)->sort($sort_column, $sort_direction)->limit($limit)->offset($offset);
     return ['list' => $selector->getQuerySelect()->getQuery()->getResult(), 'total' => $selector->getQueryTotal()->getQuery()->getSingleScalarResult()];
 }