public function testBuildBoolQuery() { $query = $this->createBoolQuery(); $this->request->expects($this->once())->method('getQuery')->will($this->returnValue($query)); $matchQuery = $this->createMatchQuery(); $filterMatchQuery = $this->createFilterQuery(); $filterMatchQuery->expects($this->once())->method('getReferenceType') ->will($this->returnValue(Filter::REFERENCE_QUERY)); $filterMatchQuery->expects($this->once())->method('getReference')->will($this->returnValue($matchQuery)); $filterQuery = $this->createFilterQuery(); $filterQuery->expects($this->once())->method('getReferenceType') ->will($this->returnValue(Filter::REFERENCE_FILTER)); $filterQuery->expects($this->once())->method('getReference')->will($this->returnValue($this->filter)); $this->request->expects($this->once())->method('getQuery')->will($this->returnValue($query)); $this->filterBuilder->expects($this->once())->method('build')->will($this->returnValue('(1)')); $this->select->expects($this->once())->method('columns')->will($this->returnValue($this->select)); $query->expects($this->once()) ->method('getMust') ->will( $this->returnValue( [ $this->createMatchQuery(), $this->createFilterQuery(), ] ) ); $query->expects($this->once()) ->method('getShould') ->will( $this->returnValue( [ $this->createMatchQuery(), $filterMatchQuery, ] ) ); $query->expects($this->once()) ->method('getMustNot') ->will( $this->returnValue( [ $this->createMatchQuery(), $filterQuery, ] ) ); $response = $this->mapper->buildQuery($this->request); $this->assertEquals($this->select, $response); }
/** * @param $query * @throws \Exception * @dataProvider buildQueryDataProvider */ public function testBuildQuery($query, $derivedQueries = []) { $this->filterBuilder->expects($this->any())->method('build')->will($this->returnValue('(1)')); $this->queryContainer->expects($this->any())->method('getDerivedQueries')->willReturn($derivedQueries); $this->select->expects($this->any())->method('columns')->will($this->returnValue($this->select)); $this->request->expects($this->once())->method('getQuery')->will($this->returnValue($query)); $response = $this->mapper->buildQuery($this->request); $this->assertEquals($this->select, $response); }
/** * @param $query * @param array $derivedQueries * @param int $queriesCount * @throws \Exception * @dataProvider buildQueryDataProvider */ public function testBuildQuery($query, array $derivedQueries = [], $queriesCount = 0) { $select = $this->createSelectMock(null, false, false); $this->mockBuilders($select); $previousSelect = $select; $selects = []; for ($i = $queriesCount; $i >= 0; $i--) { $isLast = $i === 0; $select = $this->createSelectMock($previousSelect, $isLast, true); $previousSelect = $select; $selects[] = $select; } $this->addSelects($selects); $this->request->expects($this->once())->method('getSize')->willReturn(self::REQUEST_LIMIT); $this->filterBuilder->expects($this->any())->method('build')->will($this->returnValue('(1)')); $table = $this->getMockBuilder('\\Magento\\Framework\\DB\\Ddl\\Table')->disableOriginalConstructor()->getMock(); $this->temporaryStorage->expects($this->any())->method('storeDocumentsFromSelect')->willReturn($table); $table->expects($this->any())->method('getName')->willReturn('table_name'); $this->queryContainer->expects($this->any())->method('getMatchQueries')->willReturn($derivedQueries); $this->request->expects($this->once())->method('getQuery')->will($this->returnValue($query)); $response = $this->mapper->buildQuery($this->request); $this->assertEquals(end($selects), $response); }