public function testBuildQuery() { $boost = 3.14; /** @var Select|\PHPUnit_Framework_MockObject_MockObject $select */ $select = $this->getMockBuilder('Magento\\Framework\\DB\\Select')->setMethods(['getMatchQuery', 'match'])->disableOriginalConstructor()->getMock(); $select->expects($this->once())->method('getMatchQuery')->with($this->equalTo('some_field'), $this->equalTo('-some_value'))->will($this->returnValue('matchedQuery')); $select->expects($this->once())->method('match')->with($this->equalTo('some_field'), $this->equalTo('-some_value'), $this->equalTo(true), $this->equalTo(Select::FULLTEXT_MODE_BOOLEAN)); /** @var \Magento\Framework\Search\Request\Query\Match|\PHPUnit_Framework_MockObject_MockObject $query */ $query = $this->getMockBuilder('Magento\\Framework\\Search\\Request\\Query\\Match')->setMethods(['getMatches'])->disableOriginalConstructor()->getMock(); $query->expects($this->once())->method('getMatches')->will($this->returnValue([['field' => 'some_field', 'value' => 'some_value', 'boost' => $boost]])); $this->scoreBuilder->expects($this->once())->method('addCondition')->with($this->equalTo('matchedQuery'), $this->equalTo($boost)); $result = $this->match->build($this->scoreBuilder, $select, $query, Bool::QUERY_CONDITION_NOT); $this->assertEquals($select, $result); }
public function testBuildQuery() { $boost = 3.14; /** @var Select|\PHPUnit_Framework_MockObject_MockObject $select */ $select = $this->getMockBuilder('Magento\\Framework\\DB\\Select')->setMethods(['getMatchQuery', 'match'])->disableOriginalConstructor()->getMock(); $this->fulltextHelper->expects($this->once())->method('getMatchQuery')->with($this->equalTo(['some_field']), $this->equalTo('-some_value*'))->will($this->returnValue('matchedQuery')); $this->fulltextHelper->expects($this->once())->method('match')->withConsecutive([$select, ['some_field'], '-some_value*', true, Fulltext::FULLTEXT_MODE_BOOLEAN])->willReturn($select); $this->resolver->expects($this->once())->method('resolve')->willReturnArgument(0); /** @var \Magento\Framework\Search\Request\Query\Match|\PHPUnit_Framework_MockObject_MockObject $query */ $query = $this->getMockBuilder('Magento\\Framework\\Search\\Request\\Query\\Match')->setMethods(['getMatches', 'getValue', 'getBoost'])->disableOriginalConstructor()->getMock(); $query->expects($this->once())->method('getValue')->willReturn('some_value '); $query->expects($this->once())->method('getBoost')->willReturn($boost); $query->expects($this->once())->method('getMatches')->willReturn([['field' => 'some_field']]); $this->scoreBuilder->expects($this->once())->method('addCondition'); $result = $this->match->build($this->scoreBuilder, $select, $query, Bool::QUERY_CONDITION_NOT); $this->assertEquals($select, $result); }
public function testBuildQuery() { /** @var Select|\PHPUnit_Framework_MockObject_MockObject $select */ $select = $this->getMockBuilder('Magento\Framework\DB\Select') ->setMethods(['getMatchQuery', 'match', 'where']) ->disableOriginalConstructor() ->getMock(); $this->fulltextHelper->expects($this->once()) ->method('getMatchQuery') ->with($this->equalTo(['some_field' => 'some_field']), $this->equalTo('-some_value*')) ->will($this->returnValue('matchedQuery')); $select->expects($this->once()) ->method('where') ->with('matchedQuery') ->willReturnSelf(); $this->resolver->expects($this->once()) ->method('resolve') ->willReturnCallback(function ($fieldList) { $resolvedFields = []; foreach ($fieldList as $column) { $field = $this->getMockBuilder('\Magento\Framework\Search\Adapter\Mysql\Field\FieldInterface') ->disableOriginalConstructor() ->getMockForAbstractClass(); $field->expects($this->any()) ->method('getColumn') ->willReturn($column); $resolvedFields[] = $field; } return $resolvedFields; }); /** @var \Magento\Framework\Search\Request\Query\Match|\PHPUnit_Framework_MockObject_MockObject $query */ $query = $this->getMockBuilder('Magento\Framework\Search\Request\Query\Match') ->setMethods(['getMatches', 'getValue']) ->disableOriginalConstructor() ->getMock(); $query->expects($this->once()) ->method('getValue') ->willReturn('some_value '); $query->expects($this->once()) ->method('getMatches') ->willReturn([['field' => 'some_field']]); $this->scoreBuilder->expects($this->once()) ->method('addCondition'); $result = $this->match->build($this->scoreBuilder, $select, $query, Bool::QUERY_CONDITION_NOT); $this->assertEquals($select, $result); }
public function testBuild() { $this->scoreBuilder->expects($this->once())->method('build')->willReturn('score condition'); $subSelect = $this->getMockBuilder('Magento\Framework\DB\Select') ->disableOriginalConstructor() ->getMock(); $this->indexBuilder->expects($this->once())->method('build')->willReturn($subSelect); $subSelect->expects($this->once())->method('columns')->with('score condition'); $this->request->expects($this->once())->method('getSize')->willReturn(1000); $subSelect->expects($this->once())->method('limit')->with(1000); $result = $this->queryContainer->addMatchQuery($this->select, $this->query, Bool::QUERY_CONDITION_MUST); $this->assertEquals($this->select, $result); }