public function testCreate() { $rawResponse = ['documents' => [['title' => 'oneTitle', 'description' => 'oneDescription'], ['title' => 'twoTitle', 'description' => 'twoDescription']], 'aggregations' => []]; $this->documentFactory->expects($this->at(0))->method('create')->with($this->equalTo($rawResponse['documents'][0]))->will($this->returnValue('document1')); $this->documentFactory->expects($this->at(1))->method('create')->with($rawResponse['documents'][1])->will($this->returnValue('document2')); $this->objectManager->expects($this->once())->method('create')->with($this->equalTo('Magento\\Framework\\Search\\Response\\QueryResponse'), $this->equalTo(['documents' => ['document1', 'document2'], 'aggregations' => null]))->will($this->returnValue('QueryResponseObject')); $result = $this->factory->create($rawResponse); $this->assertEquals('QueryResponseObject', $result); }
/** * Create Query Response instance * * @param mixed $rawResponse * @return QueryResponse */ public function create($rawResponse) { $documents = array(); foreach ($rawResponse['documents'] as $rawDocument) { /** @var \Magento\Framework\Search\Document[] $documents */ $documents[] = $this->documentFactory->create($rawDocument); } /** @var \Magento\Framework\Search\Aggregation $aggregations */ $aggregations = $this->documentFactory->create($rawResponse['aggregation']); return $this->objectManager->create('\\Magento\\Framework\\Search\\QueryResponse', ['documents' => $documents, 'aggregations' => $aggregations]); }