Exemple #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);
 }