/** * @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)); }
private function getReferredFixture(string $id, ResolvedFixtureSet $set) : FixtureIdInterface { $fixtures = $set->getFixtures(); if ($fixtures->has($id)) { return $fixtures->get($id); } return new FixtureId($id); }
private function generateFixtures(ResolvedFixtureSet $set, GenerationContext $context) : ResolvedFixtureSet { $fixtures = $set->getFixtures(); foreach ($fixtures as $fixture) { $objects = $this->generator->generate($fixture, $set, $context); $set = $set->withObjects($objects); } return $set; }
public function testReadAccessorsReturnPropertiesValues() { $parameters = new ParameterBag(); $fixtures = new FixtureBag(); $objects = new ObjectBag(); $set = new ResolvedFixtureSet($parameters, $fixtures, $objects); $this->assertEquals($parameters, $set->getParameters()); $this->assertEquals($fixtures, $set->getFixtures()); $this->assertEquals($objects, $set->getObjects()); }
/** * Gets all the fixture IDs suitable for the given value. * * @param FixtureMatchReferenceValue $value * @param ResolvedFixtureSet $fixtureSet * * @return string[] */ private function getSuitableIds(FixtureMatchReferenceValue $value, ResolvedFixtureSet $fixtureSet) : array { if (array_key_exists($pattern = $value->getValue(), $this->idsByPattern)) { return $this->idsByPattern[$pattern]; } $fixtureKeys = array_flip(preg_grep($pattern, array_keys($fixtureSet->getFixtures()->toArray()))); $objectKeys = array_flip(preg_grep($pattern, array_keys($fixtureSet->getObjects()->toArray()))); $this->idsByPattern[$pattern] = array_keys($fixtureKeys + $objectKeys); return $this->idsByPattern[$pattern]; }
/** * {@inheritdoc} * * @param ValueForCurrentValue $value * * @throws NoValueForCurrentException */ public function resolve(ValueInterface $value, FixtureInterface $fixture, ResolvedFixtureSet $fixtureSet, array $scope, GenerationContext $context) : ResolvedValueWithFixtureSet { return new ResolvedValueWithFixtureSet($fixtureSet->getFixtures()->get($fixture->getId()), $fixtureSet); }
/** * @param string $pattern * @param ResolvedFixtureSet $fixtureSet * * @return string[] */ private function findSuitableIds(string $pattern, ResolvedFixtureSet $fixtureSet) : array { $fixtureKeys = array_flip(preg_grep($pattern, array_keys($fixtureSet->getFixtures()->toArray()))); $objectKeys = array_flip(preg_grep($pattern, array_keys($fixtureSet->getObjects()->toArray()))); return array_keys($fixtureKeys + $objectKeys); }