public function testSearchDocumentIsConvertedIntoSolrFormat() { $documentFieldName = 'foo'; $documentFieldValue = 'bar'; $searchDocumentFieldCollection = SearchDocumentFieldCollection::fromArray([$documentFieldName => $documentFieldValue]); $contextPartName = 'baz'; $contextPartValue = 'qux'; $context = new SelfContainedContext([$contextPartName => $contextPartValue]); $productId = new ProductId(uniqid()); $searchDocument = new SearchDocument($searchDocumentFieldCollection, $context, $productId); $documentUniqueId = sprintf('%s_%s:%s', (string) $productId, $contextPartName, $contextPartValue); $expectedSolrDocument = [SolrSearchEngine::DOCUMENT_ID_FIELD_NAME => $documentUniqueId, SolrSearchEngine::PRODUCT_ID_FIELD_NAME => (string) $productId, $documentFieldName => [$documentFieldValue], $contextPartName => $contextPartValue]; $this->assertSame($expectedSolrDocument, SolrDocumentBuilder::fromSearchDocument($searchDocument)); }
public function testExceptionIsThrownIfMessageCouldNotBeWritten() { self::$diskIsFull = true; $this->expectException(SearchDocumentCanNotBeStoredException::class); /** @var FacetFieldTransformationRegistry|MockObject $stubFacetFieldTransformationRegistry */ $stubFacetFieldTransformationRegistry = $this->createMock(FacetFieldTransformationRegistry::class); $searchEngine = $this->createSearchEngineInstance($stubFacetFieldTransformationRegistry); $testSearchDocument = new SearchDocument(SearchDocumentFieldCollection::fromArray([]), new SelfContainedContext([]), new ProductId('foo')); $searchEngine->addDocument($testSearchDocument); }
private function createSearchDocumentFormJson(string $json) : SearchDocument { $searchDocumentArrayRepresentation = json_decode($json, true); $context = $this->createContextFromDataSet($searchDocumentArrayRepresentation[self::CONTEXT]); $searchDocumentFields = SearchDocumentFieldCollection::fromArray($searchDocumentArrayRepresentation[self::FIELDS]); $productId = new ProductId($searchDocumentArrayRepresentation[self::PRODUCT_ID]); return new SearchDocument($searchDocumentFields, $context, $productId); }
/** * @param SearchDocumentFieldCollection $fieldCollection * @return array[] */ private static function getSearchDocumentFields(SearchDocumentFieldCollection $fieldCollection) : array { return array_reduce($fieldCollection->getFields(), function ($carry, SearchDocumentField $field) { return array_merge([$field->getKey() => $field->getValues()], $carry); }, []); }
public function testUpdateRequestContainingSolrDocumentsIsSentToHttpClient() { $searchDocumentFieldCollection = SearchDocumentFieldCollection::fromArray(['foo' => 'bar']); $context = new SelfContainedContext(['baz' => 'qux']); $productId = new ProductId(uniqid()); $searchDocument = new SearchDocument($searchDocumentFieldCollection, $context, $productId); $expectedSolrDocument = SolrDocumentBuilder::fromSearchDocument($searchDocument); $this->mockHttpClient->expects($this->once())->method('update')->with([$expectedSolrDocument]); $this->searchEngine->addDocument($searchDocument); }