generate() public method

Generates a fixture.
public generate ( Nelmio\Alice\FixtureInterface $fixture, ResolvedFixtureSet $fixtureSet, GenerationContext $context ) : ObjectBag
$fixture Nelmio\Alice\FixtureInterface Fixture to generate
$fixtureSet ResolvedFixtureSet List of fixtures being generated
$context GenerationContext
return Nelmio\Alice\ObjectBag New instance of $objects with the objects generated when generating $fixture.
Beispiel #1
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;
 }
 /**
  * @inheritdoc
  */
 public function generate(FixtureInterface $fixture, ResolvedFixtureSet $fixtureSet, GenerationContext $context) : ObjectBag
 {
     if ($fixtureSet->getObjects()->has($fixture) && $fixtureSet->getObjects()->get($fixture) instanceof CompleteObject) {
         return $fixtureSet->getObjects();
     }
     $objects = $this->objectGenerator->generate($fixture, $fixtureSet, $context);
     $generatedObject = $objects->get($fixture);
     if (false === $this->isObjectComplete($fixture, $generatedObject, $context)) {
         return $objects;
     }
     return $objects->with(new CompleteObject($generatedObject));
 }
 /**
  * @param FixtureIdInterface|FixtureInterface $referredFixture
  * @param string                              $referredFixtureId
  * @param ResolvedFixtureSet                  $fixtureSet
  * @param GenerationContext                   $context
  *
  * @return ResolvedValueWithFixtureSet
  */
 private function resolveReferredFixture(FixtureIdInterface $referredFixture, string $referredFixtureId, ResolvedFixtureSet $fixtureSet, GenerationContext $context) : ResolvedValueWithFixtureSet
 {
     if ($fixtureSet->getObjects()->has($referredFixture)) {
         $referredObject = $fixtureSet->getObjects()->get($referredFixture);
         if ($referredObject instanceof CompleteObject || false === $context->needsCompleteGeneration()) {
             return new ResolvedValueWithFixtureSet($referredObject->getInstance(), $fixtureSet);
         }
     }
     // Object is either not completely generated or has not been generated at all yet
     if (false === $referredFixture instanceof FixtureInterface) {
         throw FixtureNotFoundExceptionFactory::create($referredFixtureId);
     }
     $context->markIsResolvingFixture($referredFixtureId);
     $objects = $this->generator->generate($referredFixture, $fixtureSet, $context);
     $fixtureSet = $fixtureSet->withObjects($objects);
     return new ResolvedValueWithFixtureSet($fixtureSet->getObjects()->get($referredFixture)->getInstance(), $fixtureSet);
 }