/** * Constructs a SqlQuery instance from the current specifications of the builder. * * @return SqlQuery */ public function getQuery() { $query = new SqlQuery($this->em); $query->setQueryBuilder($this->qb); $query->setResultSetMapping($this->rsm); return $query; }
/** * @param string $sql * @param bool $useWalker * * @dataProvider getSqlCountDataProvider */ public function testCalculateCountForSqlQuery($sql, $useWalker) { /** @var $entityManager EntityManager|\PHPUnit_Framework_MockObject_MockObject */ /** @var $statement Statement|\PHPUnit_Framework_MockObject_MockObject */ list($entityManager, , $statement) = $this->prepareMocks(); $dbalQb = $this->getMock('Doctrine\\DBAL\\Query\\QueryBuilder', ['getSQL', 'resetQueryParts', 'select', 'from', 'execute'], [], '', false); $query = new SqlQuery($entityManager); $query->setQueryBuilder($dbalQb); $dbalQb->expects($this->once())->method('getSQL')->will($this->returnValue($sql)); $dbalQb->expects($this->once())->method('resetQueryParts')->will($this->returnSelf()); $dbalQb->expects($this->once())->method('select')->with('COUNT(*)')->will($this->returnSelf()); $dbalQb->expects($this->once())->method('from')->with('(' . $sql . ')', 'e')->will($this->returnSelf()); $dbalQb->expects($this->once())->method('execute')->will($this->returnValue($statement)); $statement->expects($this->once())->method('fetchColumn')->will($this->returnValue(self::TEST_COUNT)); $this->assertEquals(self::TEST_COUNT, QueryCountCalculator::calculateCount($query, $useWalker)); }
public function testHandleWithSqlQuery() { $testCount = 22; $query = new SqlQuery($this->getMock('Doctrine\\ORM\\EntityManager', [], [], '', false)); $dbalQb = $this->getMock('Doctrine\\DBAL\\Query\\QueryBuilder', ['setMaxResults', 'setFirstResult'], [], '', false); $query->setQueryBuilder($dbalQb); $dbalQb->expects($this->once())->method('setMaxResults')->with($this->identicalTo(null))->will($this->returnSelf()); $dbalQb->expects($this->once())->method('setFirstResult')->with($this->identicalTo(null))->will($this->returnSelf()); $this->handler->expects($this->once())->method('calculateCount')->with($this->isInstanceOf('Oro\\Bundle\\EntityBundle\\ORM\\SqlQuery'))->willReturn($testCount); $context = $this->createContext(); $context->set('query', $query); $this->handler->handle($context); $response = $context->getResponse(); $this->assertSame($testCount, $response->headers->get(TotalHeaderHandler::HEADER_NAME)); }
public function testHandleWithSqlQuery() { $testCount = 22; $configuration = $this->getMockBuilder('Doctrine\\ORM\\Configuration')->disableOriginalConstructor()->getMock(); $configuration->expects($this->any())->method('getDefaultQueryHints')->will($this->returnValue([])); $configuration->expects($this->once())->method('isSecondLevelCacheEnabled')->will($this->returnValue(false)); $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $em->expects($this->any())->method('getConfiguration')->will($this->returnValue($configuration)); $query = new SqlQuery($em); $dbalQb = $this->getMock('Doctrine\\DBAL\\Query\\QueryBuilder', ['setMaxResults', 'setFirstResult'], [], '', false); $query->setQueryBuilder($dbalQb); $dbalQb->expects($this->once())->method('setMaxResults')->with($this->identicalTo(null))->will($this->returnSelf()); $dbalQb->expects($this->once())->method('setFirstResult')->with($this->identicalTo(null))->will($this->returnSelf()); $this->handler->expects($this->once())->method('calculateCount')->with($this->isInstanceOf('Oro\\Component\\DoctrineUtils\\ORM\\SqlQuery'))->willReturn($testCount); $context = $this->createContext(); $context->set('query', $query); $this->handler->handle($context); $response = $context->getResponse(); $this->assertSame($testCount, $response->headers->get(TotalHeaderHandler::HEADER_NAME)); }