/**
  * @test
  */
 public function canBuildAggregate()
 {
     $matchingRuleA = new MatchingRule();
     $matchingRuleA->setFieldName('brand');
     $matchingRuleA->setOperator(MatchingRule::OPERATOR_EQUALS);
     $matchingRuleA->setOperandValue('aoe');
     $matchingRuleB = new MatchingRule();
     $matchingRuleB->setFieldName('brand');
     $matchingRuleB->setOperator(MatchingRule::OPERATOR_CONTAINSNOT);
     $matchingRuleB->setOperandValue('nasa');
     $fieldEnrichment = new FieldEnrichment();
     $fieldEnrichment->setFieldName('boostwords');
     $fieldEnrichment->setContent('very important');
     $contextsBoostingArrayOfObjects = $this->generateContextsBoosting('brands', 'nike', 'in_stock', true, 3.45, 3);
     $this->enrichment->addMatchingRule($matchingRuleA)->addMatchingRule($matchingRuleB);
     $this->enrichment->addFieldEnrichment($fieldEnrichment);
     $this->enrichment->addContextsBoosting($contextsBoostingArrayOfObjects[0])->addContextsBoosting($contextsBoostingArrayOfObjects[1])->addContextsBoosting($contextsBoostingArrayOfObjects[2]);
     $this->assertEquals(2, $this->enrichment->getMatchingRules()->getCount());
     $this->assertEquals(3, $this->enrichment->getContextsBoosting()->getCount());
     $this->assertEquals(4.45, $this->enrichment->getContextsBoosting()->offsetGet(1)->getBoostingValue());
 }
 /**
  * @param \SimpleXMLElement $xml
  *
  * @return \Searchperience\Api\Client\Domain\Enrichment\EnrichmentCollection
  */
 protected function buildEnrichmentsFromXml(\SimpleXMLElement $xml)
 {
     $enrichmentCollection = new EnrichmentCollection();
     if ($xml->totalCount instanceof \SimpleXMLElement) {
         $enrichmentCollection->setTotalCount((int) $xml->totalCount->__toString());
     }
     $enrichments = $xml->xpath('enrichment');
     foreach ($enrichments as $enrichment) {
         $enrichmentAttributeArray = (array) $enrichment->attributes();
         $enrichmentObject = new \Searchperience\Api\Client\Domain\Enrichment\Enrichment();
         $enrichmentObject->__setProperty('id', (int) $enrichmentAttributeArray['@attributes']['id']);
         $enrichmentObject->__setProperty('title', (string) $enrichment->title);
         $enrichmentObject->__setProperty('addBoost', (string) $enrichment->addBoost);
         $enrichmentObject->__setProperty('description', (string) $enrichment->description);
         $enrichmentObject->__setProperty('enabled', (bool) (int) $enrichment->status);
         if (isset($enrichment->matchingrules->matchingrule)) {
             foreach ($enrichment->matchingrules->matchingrule as $matchingrule) {
                 $matchingRuleObject = new \Searchperience\Api\Client\Domain\Enrichment\MatchingRule();
                 $matchingRuleObject->__setProperty('operator', (string) $matchingrule->operator);
                 $matchingRuleObject->__setProperty('fieldName', (string) $matchingrule->fieldName);
                 $matchingRuleObject->__setProperty('operandValue', (string) $matchingrule->operandValue);
                 $matchingRules = $enrichmentObject->getMatchingRules();
                 $matchingRules->append($matchingRuleObject);
                 $matchingRuleObject->afterReconstitution();
                 $enrichmentObject->__setProperty('matchingRules', $matchingRules);
             }
         }
         if (isset($enrichment->fieldenrichments->fieldenrichment)) {
             foreach ($enrichment->fieldenrichments->fieldenrichment as $fieldenrichment) {
                 $fieldEnrichmentObject = new \Searchperience\Api\Client\Domain\Enrichment\FieldEnrichment();
                 $fieldEnrichmentObject->__setProperty('fieldName', (string) $fieldenrichment->fieldName);
                 $fieldEnrichmentObject->__setProperty('content', (string) $fieldenrichment->content);
                 $fieldEnrichments = $enrichmentObject->getFieldEnrichments();
                 $fieldEnrichments->append($fieldEnrichmentObject);
                 $fieldEnrichmentObject->afterReconstitution();
                 $enrichmentObject->__setProperty('fieldEnrichments', $fieldEnrichments);
             }
         }
         if (isset($enrichment->contextsBoosting->context)) {
             foreach ($enrichment->contextsBoosting->context as $context) {
                 $contextsBoostingObject = new ContextsBoosting();
                 $contextsBoostingObject->__setProperty('boostFieldName', (string) $context->boostFieldName);
                 $contextsBoostingObject->__setProperty('boostFieldValue', (string) $context->boostFieldValue);
                 $contextsBoostingObject->__setProperty('boostOptionName', (string) $context->boostOptionName);
                 $contextsBoostingObject->__setProperty('boostOptionValue', (bool) (int) $context->boostOptionValue);
                 $contextsBoostingObject->__setProperty('boostingValue', (double) $context->boostingValue);
                 $contextsBoosting = $enrichmentObject->getContextsBoosting();
                 $contextsBoosting->append($contextsBoostingObject);
                 $contextsBoostingObject->afterReconstitution();
                 $enrichmentObject->__setProperty('contextsBoosting', $contextsBoosting);
             }
         }
         $enrichmentObject->afterReconstitution();
         $enrichmentCollection->append($enrichmentObject);
     }
     return $enrichmentCollection;
 }