6 declare(strict_types=1);
36 private $connectionManager;
46 private $clientConfig;
51 private $storeManager;
56 private $customerSession;
71 private $searchIndexNameResolver;
78 $this->connectionManager = $this->getMockBuilder(ConnectionManager::class)
79 ->setMethods([
'getConnection'])
80 ->disableOriginalConstructor()
82 $this->fieldMapper = $this->getMockBuilder(FieldMapperInterface::class)
83 ->disableOriginalConstructor()
85 $this->clientConfig = $this->getMockBuilder(Config::class)
90 ->disableOriginalConstructor()
92 $this->storeManager = $this->getMockBuilder(StoreManagerInterface::class)
93 ->disableOriginalConstructor()
95 $this->customerSession = $this->getMockBuilder(CustomerSession::class)
96 ->setMethods([
'getCustomerGroupId'])
97 ->disableOriginalConstructor()
99 $this->customerSession->expects($this->any())
100 ->method(
'getCustomerGroupId')
102 $this->storeMock = $this->getMockBuilder(StoreInterface::class)
103 ->disableOriginalConstructor()
105 $this->searchIndexNameResolver = $this
106 ->getMockBuilder(SearchIndexNameResolver::class)
107 ->disableOriginalConstructor()
109 $this->storeMock->expects($this->any())
110 ->method(
'getWebsiteId')
112 $this->storeMock->expects($this->any())
115 $this->clientConfig->expects($this->any())
116 ->method(
'getIndexName')
117 ->willReturn(
'indexName');
118 $this->clientConfig->expects($this->any())
119 ->method(
'getEntityType')
120 ->willReturn(
'product');
121 $this->clientMock = $this->getMockBuilder(ElasticsearchClient::class)
122 ->setMethods([
'query'])
123 ->disableOriginalConstructor()
125 $this->connectionManager->expects($this->any())
126 ->method(
'getConnection')
127 ->willReturn($this->clientMock);
129 $objectManagerHelper =
new ObjectManagerHelper($this);
130 $this->model = $objectManagerHelper->getObject(
133 'connectionManager' => $this->connectionManager,
134 'fieldMapper' => $this->fieldMapper,
135 'clientConfig' => $this->clientConfig,
136 'searchIndexNameResolver' => $this->searchIndexNameResolver,
137 'fieldName' =>
'price_0_1',
139 'entityIds' => [265, 313, 281],
162 $this->processQuery($queryResult);
166 $this->model->load($limit, $offset, $lower, $upper)
181 $this->processQuery($queryResult);
198 public function testLoadNext(
string $data,
string $rightIndex,
string $upper, array $queryResult, $expected): void
200 $this->processQuery($queryResult);
204 $this->model->loadNext(
$data, $rightIndex, $upper)
212 private function processQuery(array $queryResult): void
214 $this->searchIndexNameResolver->expects($this->any())
215 ->method(
'getIndexName')
216 ->willReturn(
'magento2_product_1');
217 $this->clientConfig->expects($this->any())
218 ->method(
'getEntityType')
219 ->willReturn(
'document');
220 $this->clientMock->expects($this->any())
222 ->willReturn($queryResult);
268 'price_0_1' => [
'25'],
274 'expected' => [
'25.0'],
281 'hits' => [
'total'=>
'0'],
304 'price_0_1' => [
'25'],
310 'expected' => [
'25.0'],
317 'hits' => [
'total'=>
'0'],
testLoadPrev(string $data, string $index, string $lower, array $queryResult, $expected)
testLoadNext(string $data, string $rightIndex, string $upper, array $queryResult, $expected)
testLoad(string $limit, string $offset, string $lower, string $upper, array $queryResult, array $expected)