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);
    }
Esempio n. 2
0
 /**
  * @param Select $select
  */
 private function mockBuilders(Select $select)
 {
     $helper = new ObjectManager($this);
     $this->scoreBuilder = $this->getMockBuilder('Magento\\Framework\\Search\\Adapter\\Mysql\\ScoreBuilder')->setMethods(['clear'])->disableOriginalConstructor()->getMock();
     $this->scoreBuilderFactory = $this->getMockBuilder('Magento\\Framework\\Search\\Adapter\\Mysql\\ScoreBuilderFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $this->scoreBuilderFactory->expects($this->any())->method('create')->will($this->returnValue($this->scoreBuilder));
     $this->filterBuilder = $this->getMockBuilder('Magento\\Framework\\Search\\Adapter\\Mysql\\Filter\\Builder')->setMethods(['build'])->disableOriginalConstructor()->getMock();
     $this->matchBuilder = $this->getMockBuilder('\\Magento\\Framework\\Search\\Adapter\\Mysql\\Query\\Builder\\Match')->setMethods(['build'])->disableOriginalConstructor()->getMock();
     $this->matchBuilder->expects($this->any())->method('build')->willReturnArgument(1);
     $this->indexBuilder = $this->getMockBuilder('\\Magento\\Framework\\Search\\Adapter\\Mysql\\IndexBuilderInterface')->disableOriginalConstructor()->setMethods(['build'])->getMockForAbstractClass();
     $this->indexBuilder->expects($this->any())->method('build')->will($this->returnValue($select));
     $temporaryStorageFactory = $this->getMockBuilder('\\Magento\\Framework\\Search\\Adapter\\Mysql\\TemporaryStorageFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $temporaryStorageFactory->expects($this->any())->method('create')->willReturn($this->temporaryStorage);
     $queryContainerFactory = $this->getMockBuilder('Magento\\Framework\\Search\\Adapter\\Mysql\\Query\\QueryContainerFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $queryContainerFactory->expects($this->any())->method('create')->willReturn($this->queryContainer);
     $entityMetadata = $this->getMockBuilder('\\Magento\\Framework\\Search\\EntityMetadata')->setMethods(['getEntityId'])->disableOriginalConstructor()->getMock();
     $entityMetadata->expects($this->any())->method('getEntityId')->willReturn(self::METADATA_ENTITY_ID);
     $this->mapper = $helper->getObject('Magento\\Framework\\Search\\Adapter\\Mysql\\Mapper', ['resource' => $this->resource, 'scoreBuilderFactory' => $this->scoreBuilderFactory, 'queryContainerFactory' => $queryContainerFactory, 'filterBuilder' => $this->filterBuilder, 'matchBuilder' => $this->matchBuilder, 'indexProviders' => [self::INDEX_NAME => $this->indexBuilder], 'temporaryStorageFactory' => $temporaryStorageFactory, 'entityMetadata' => $entityMetadata]);
 }