Example #1
0
 protected function setUp()
 {
     $helper = new ObjectManager($this);
     $this->select = $this->getMockBuilder('Magento\\Framework\\DB\\Select')->setMethods(['group', 'limit', 'where', 'columns', 'from', 'join'])->disableOriginalConstructor()->getMock();
     $this->select->expects($this->any())->method('from')->willReturnSelf();
     $connectionAdapter = $this->getMockBuilder('Magento\\Framework\\DB\\Adapter\\AdapterInterface')->setMethods(['select'])->disableOriginalConstructor()->getMockForAbstractClass();
     $connectionAdapter->expects($this->any())->method('select')->will($this->returnValue($this->select));
     $this->resource = $this->getMockBuilder('Magento\\Framework\\App\\Resource')->disableOriginalConstructor()->getMock();
     $this->resource->expects($this->any())->method('getConnection')->with(Resource::DEFAULT_READ_RESOURCE)->will($this->returnValue($connectionAdapter));
     $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->request = $this->getMockBuilder('Magento\\Framework\\Search\\RequestInterface')->setMethods(['getQuery', 'getIndex', 'getSize'])->disableOriginalConstructor()->getMockForAbstractClass();
     $this->queryContainer = $this->getMockBuilder('Magento\\Framework\\Search\\Adapter\\Mysql\\Query\\QueryContainer')->setMethods(['addMatchQuery', 'getDerivedQueries'])->disableOriginalConstructor()->getMock();
     $this->queryContainer->expects($this->any())->method('addMatchQuery')->willReturnArgument(0);
     $queryContainerFactory = $this->getMockBuilder('Magento\\Framework\\Search\\Adapter\\Mysql\\Query\\QueryContainerFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $queryContainerFactory->expects($this->any())->method('create')->willReturn($this->queryContainer);
     $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);
     /** @var MockObject|\Magento\Framework\Search\Adapter\Mysql\IndexBuilderInterface $indexBuilder */
     $indexBuilder = $this->getMockBuilder('\\Magento\\Framework\\Search\\Adapter\\Mysql\\IndexBuilderInterface')->disableOriginalConstructor()->setMethods(['build'])->getMockForAbstractClass();
     $indexBuilder->expects($this->any())->method('build')->will($this->returnValue($this->select));
     $index = self::INDEX_NAME;
     $this->request->expects($this->exactly(2))->method('getIndex')->will($this->returnValue($index));
     $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' => [$index => $indexBuilder]]);
 }
    protected function setUp()
    {
        $helper = new ObjectManager($this);

        $this->select = $this->getMockBuilder('Magento\Framework\DB\Select')
            ->disableOriginalConstructor()
            ->getMock();

        $this->scoreBuilder = $this->getMockBuilder('Magento\Framework\Search\Adapter\Mysql\ScoreBuilder')
            ->disableOriginalConstructor()
            ->getMock();
        $this->scoreBuilderFactory = $this->getMockBuilder('Magento\Framework\Search\Adapter\Mysql\ScoreBuilderFactory')
            ->setMethods(['create'])
            ->disableOriginalConstructor()
            ->getMock();
        $this->scoreBuilderFactory->expects($this->any())->method('create')->willReturn($this->scoreBuilder);

        $this->query = $this->getMockBuilder('Magento\Framework\Search\Request\QueryInterface')
            ->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')
            ->setMethods(['build'])
            ->disableOriginalConstructor()
            ->getMock();

        $this->request = $this->getMockBuilder('\Magento\Framework\Search\RequestInterface')
            ->disableOriginalConstructor()
            ->getMock();

        $this->queryContainer = $helper->getObject(
            'Magento\Framework\Search\Adapter\Mysql\Query\QueryContainer',
            [
                'scoreBuilderFactory' => $this->scoreBuilderFactory,
                'matchBuilder' => $this->matchBuilder,
                'indexBuilder' => $this->indexBuilder,
                'request' => $this->request
            ]
        );
    }
 protected function setUp()
 {
     $helper = new ObjectManager($this);
     $this->select = $this->getMockBuilder('Magento\\Framework\\DB\\Select')->setMethods([])->disableOriginalConstructor()->getMock();
     $connectionAdapter = $this->getMockBuilder('Magento\\Framework\\DB\\Adapter\\AdapterInterface')->setMethods(['select'])->disableOriginalConstructor()->getMockForAbstractClass();
     $connectionAdapter->expects($this->any())->method('select')->will($this->returnValue($this->select));
     $this->resource = $this->getMockBuilder('Magento\\Framework\\App\\Resource')->setMethods(['getConnection'])->disableOriginalConstructor()->getMock();
     $this->resource->expects($this->any())->method('getConnection')->with(Resource::DEFAULT_READ_RESOURCE)->will($this->returnValue($connectionAdapter));
     $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->dimensionsBuilder = $this->getMockBuilder('\\Magento\\Framework\\Search\\Adapter\\Mysql\\Dimensions')->setMethods(['build'])->disableOriginalConstructor()->getMock();
     $this->request = $this->getMockBuilder('Magento\\Framework\\Search\\RequestInterface')->setMethods(['getQuery', 'getDimensions'])->disableOriginalConstructor()->getMockForAbstractClass();
     $this->matchQueryBuilder = $this->getMockBuilder('Magento\\Framework\\Search\\Adapter\\Mysql\\Query\\Builder\\Match')->setMethods(['build'])->disableOriginalConstructor()->getMock();
     $this->filter = $this->getMockBuilder('Magento\\Framework\\Search\\Request\\FilterInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $this->filterBuilder = $this->getMockBuilder('Magento\\Framework\\Search\\Adapter\\Mysql\\Filter\\Builder')->setMethods(['build'])->disableOriginalConstructor()->getMock();
     $this->mapper = $helper->getObject('Magento\\Framework\\Search\\Adapter\\Mysql\\Mapper', ['resource' => $this->resource, 'scoreBuilderFactory' => $this->scoreBuilderFactory, 'matchQueryBuilder' => $this->matchQueryBuilder, 'filterBuilder' => $this->filterBuilder, 'dimensionsBuilder' => $this->dimensionsBuilder]);
 }
 /**
  * @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]);
 }