getFixtures() public method

public getFixtures ( ) : FixtureBag
return Nelmio\Alice\FixtureBag
Ejemplo n.º 1
0
 /**
  * @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));
 }
Ejemplo n.º 2
0
 private function getReferredFixture(string $id, ResolvedFixtureSet $set) : FixtureIdInterface
 {
     $fixtures = $set->getFixtures();
     if ($fixtures->has($id)) {
         return $fixtures->get($id);
     }
     return new FixtureId($id);
 }
Ejemplo n.º 3
0
 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;
 }
Ejemplo n.º 4
0
 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];
 }
Ejemplo n.º 6
0
 /**
  * {@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);
 }