create() public static method

public static create ( string $id ) : FixtureNotFoundException
$id string
return FixtureNotFoundException
Example #1
0
 public function getTemplate(string $id) : FixtureInterface
 {
     if ($this->templates->has($id)) {
         return $this->templates->get($id);
     }
     throw FixtureNotFoundExceptionFactory::create($id);
 }
Example #2
0
 /**
  * @param string $id Fixture ID.
  *
  * @throws FixtureNotFoundException
  *
  * @return FixtureInterface
  */
 public function get(string $id) : FixtureInterface
 {
     if ($this->has($id)) {
         return clone $this->fixtures[$id];
     }
     throw FixtureNotFoundExceptionFactory::create($id);
 }
Example #3
0
 /**
  * @param TemplatingFixture    $fixture
  * @param FixtureReference[]   $extendedFixtureReferences
  * @param FixtureBag           $unresolvedFixtures
  * @param TemplatingFixtureBag $resolvedFixtures
  * @param ResolvingContext     $context
  *
  * @throws FixtureNotFoundException
  *
  * @return array The first element is a FixtureBag with all the extended fixtures and the second is a
  *               TemplatingFixtureBag which may contain new fixtures (from the resolution)
  */
 private function resolveExtendedFixtures(TemplatingFixture $fixture, array $extendedFixtureReferences, FixtureBag $unresolvedFixtures, TemplatingFixtureBag $resolvedFixtures, ResolvingContext $context) : array
 {
     $fixtures = new FixtureBag();
     foreach ($extendedFixtureReferences as $reference) {
         $fixtureId = $reference->getId();
         $context->add($fixtureId);
         if (false === $unresolvedFixtures->has($fixtureId)) {
             throw FixtureNotFoundExceptionFactory::create($fixtureId);
         }
         if ($resolvedFixtures->has($fixtureId)) {
             if (false === $resolvedFixtures->hasTemplate($fixtureId)) {
                 throw InvalidArgumentExceptionFactory::createForFixtureExtendingANonTemplateFixture($fixture, $fixtureId);
             }
             $fixtures = $fixtures->with($resolvedFixtures->getTemplate($fixtureId));
             continue;
         }
         $unresolvedFixture = $unresolvedFixtures->get($fixtureId);
         if (false === $unresolvedFixture instanceof TemplatingFixture) {
             throw InvalidArgumentExceptionFactory::createForFixtureExtendingANonTemplateFixture($fixture, $fixtureId);
         }
         $resolvedFixtures = $this->resolve($unresolvedFixtures->get($fixtureId), $unresolvedFixtures, $resolvedFixtures, $context);
         $fixtures = $fixtures->with($resolvedFixtures->get($fixtureId));
     }
     return [$fixtures, $resolvedFixtures];
 }
 /**
  * @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);
 }