public function testQuery() { $selectResult = ['documents' => [['product_id' => 1, 'sku' => 'Product']], 'aggregations' => ['aggregation_name' => ['aggregation1' => [1, 3], 'aggregation2' => [2, 4]]]]; $this->connectionAdapter->expects($this->at(0))->method('fetchAssoc')->will($this->returnValue($selectResult['documents'])); $this->mapper->expects($this->once())->method('buildQuery')->with($this->request)->will($this->returnValue($this->select)); $this->responseFactory->expects($this->once())->method('create')->with($selectResult)->will($this->returnArgument(0)); $this->aggregatioBuilder->expects($this->once())->method('build')->willReturn($selectResult['aggregations']); $response = $this->adapter->query($this->request); $this->assertEquals($selectResult, $response); }
public function testQuery() { $selectResult = ['documents' => [['product_id' => 1, 'sku' => 'Product']], 'aggregations' => ['aggregation_name' => ['aggregation1' => [1, 3], 'aggregation2' => [2, 4]]]]; $select = $this->getMockBuilder('Magento\\Framework\\DB\\Select')->disableOriginalConstructor()->getMock(); $this->connectionAdapter->expects($this->once())->method('select')->willReturn($select); $table = $this->getMockBuilder('Magento\\Framework\\DB\\Ddl\\Table')->disableOriginalConstructor()->getMock(); $this->temporaryStorage->expects($this->any())->method('storeDocumentsFromSelect')->willReturn($table); $this->connectionAdapter->expects($this->any())->method('fetchAssoc')->will($this->returnValue($selectResult['documents'])); $this->mapper->expects($this->once())->method('buildQuery')->with($this->request)->will($this->returnValue($this->select)); $this->responseFactory->expects($this->once())->method('create')->with($selectResult)->will($this->returnArgument(0)); $this->aggregatioBuilder->expects($this->once())->method('build')->willReturn($selectResult['aggregations']); $response = $this->adapter->query($this->request); $this->assertEquals($selectResult, $response); }