/** * @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)); }
public function testTestCreateFromResolutionThrowable() { $previous = new RootResolutionException(); $exception = UnresolvableValueDuringGenerationExceptionFactory::createFromResolutionThrowable($previous); $this->assertEquals('Could not resolve value during the generation process.', $exception->getMessage()); $this->assertEquals(0, $exception->getCode()); $this->assertSame($previous, $exception->getPrevious()); }
/** * @param array $arguments * @param ValueResolverInterface $resolver * @param FixtureInterface $fixture * @param ResolvedFixtureSet $fixtureSet * @param GenerationContext $context * * @throws UnresolvableValueDuringGenerationException * * @return array The first element is an array ($arguments) which is the resolved arguments and the second the new * ResolvedFixtureSet which may contains new fixtures (from the arguments resolution) */ private function resolveArguments(array $arguments, ValueResolverInterface $resolver, FixtureInterface $fixture, ResolvedFixtureSet $fixtureSet, GenerationContext $context) : array { foreach ($arguments as $index => $argument) { if ($argument instanceof ValueInterface) { try { $result = $resolver->resolve($argument, $fixture, $fixtureSet, [], $context); } catch (ResolutionThrowable $throwable) { throw UnresolvableValueDuringGenerationExceptionFactory::createFromResolutionThrowable($throwable); } $fixtureSet = $result->getSet(); $arguments[$index] = $result->getValue(); } } return [$arguments, $fixtureSet]; }