ProductSearchBuilder example

$request->query->set('search', $query);
        $context = Context::createDefaultContext();
        $mockSalesChannelContext = $this->createMock(SalesChannelContext::class);
        $mockSalesChannelContext->method('getContext')->willReturn($context);

        $mockProductSearchBuilder = $this->createMock(ProductSearchBuilder::class);
        $mockProductSearchBuilder->method('build')->willThrowException(new \Exception('Should not be called'));

        $mockElasticsearchHelper = $this->createMock(ElasticsearchHelper::class);
        $mockElasticsearchHelper->expects(static::once())->method('allowSearch')->with($productDefinition$context$criteria)->willReturn(true);

        $searchBuilder = new ProductSearchBuilder(
            $mockProductSearchBuilder,
            $mockElasticsearchHelper,
            $productDefinition
        );

        $searchBuilder->build($request$criteria$mockSalesChannelContext);

        static::assertNotEquals('array', $criteria->getTerm());
        static::assertEquals($expected$criteria->getTerm());
    }

    
Home | Imprint | This part of the site doesn't use cookies.