/**
* @inheritdoc
*/
public function hydrate(ObjectInterface $object, ResolvedFixtureSet $fixtureSet, GenerationContext $context) : ResolvedFixtureSet
{
if (null === $this->resolver) {
throw ResolverNotFoundExceptionFactory::createUnexpectedCall(__METHOD__);
}
$fixture = $fixtureSet->getFixtures()->get($object->getId());
$properties = $fixture->getSpecs()->getProperties();
$scope = ['_instances' => $fixtureSet->getObjects()->toArray()];
foreach ($properties as $property) {
/** @var Property $property */
$propertyValue = $property->getValue();
if ($propertyValue instanceof ValueInterface) {
try {
$result = $this->resolver->resolve($propertyValue, $fixture, $fixtureSet, $scope, $context);
} catch (ResolutionThrowable $throwable) {
throw UnresolvableValueDuringGenerationExceptionFactory::createFromResolutionThrowable($throwable);
}
list($propertyValue, $fixtureSet) = [$result->getValue(), $result->getSet()];
$property = $property->withValue($propertyValue);
}
$scope[$property->getName()] = $propertyValue;
$object = $this->hydrator->hydrate($object, $property, $context);
}
return $fixtureSet->withObjects($fixtureSet->getObjects()->with($object));
}