Exemplo n.º 1
0
 public function getTemplate(string $id) : FixtureInterface
 {
     if ($this->templates->has($id)) {
         return $this->templates->get($id);
     }
     throw FixtureNotFoundExceptionFactory::create($id);
 }
Exemplo n.º 2
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];
 }
Exemplo n.º 3
0
 /**
  * @inheritdoc
  */
 public function denormalize(FixtureBag $builtFixtures, string $className, string $unparsedFixtureId, array $specs, FlagBag $flags) : FixtureBag
 {
     if (null === $this->flagParser) {
         throw FlagParserExceptionFactory::createForExpectedMethodToBeCalledIfHasAParser(__METHOD__);
     }
     $idFlags = $this->flagParser->parse($unparsedFixtureId);
     $fixture = new SimpleFixture($idFlags->getKey(), $className, new SpecificationBag(null, new PropertyBag(), new MethodCallBag()));
     $fixture = $fixture->withSpecs($this->specsDenormalizer->denormalize($fixture, $this->flagParser, $specs));
     return $builtFixtures->with(new TemplatingFixture(new SimpleFixtureWithFlags($fixture, $idFlags->mergeWith($flags))));
 }
Exemplo n.º 4
0
 public function testWithersReturnNewModifiedInstance()
 {
     $fixture = new DummyFixture('foo');
     $bag = new FixtureBag();
     $newBag = $bag->with($fixture);
     $newBagEmptied = $newBag->without($fixture);
     $this->assertInstanceOf(FixtureBag::class, $newBag);
     $this->assertNotSame($newBag, $bag);
     $this->assertEquals(new FixtureBag(), $bag);
     $this->assertSameFixtures(['foo' => $fixture], $newBag);
     $this->assertEquals(new FixtureBag(), $newBagEmptied);
 }
 public function testDenormalizesASetOfDataIntoAFixtureBag()
 {
     $fixture1Prophecy = $this->prophesize(FixtureInterface::class);
     $fixture1Prophecy->getId()->willReturn('user_alice');
     /** @var FixtureInterface $fixture1 */
     $fixture1 = $fixture1Prophecy->reveal();
     $fixture2Prophecy = $this->prophesize(FixtureInterface::class);
     $fixture2Prophecy->getId()->willReturn('user_bob');
     /** @var FixtureInterface $fixture2 */
     $fixture2 = $fixture2Prophecy->reveal();
     $fixture3Prophecy = $this->prophesize(FixtureInterface::class);
     $fixture3Prophecy->getId()->willReturn('owern1');
     /** @var FixtureInterface $fixture3 */
     $fixture3 = $fixture3Prophecy->reveal();
     $data = ['Nelmio\\Entity\\User (dummy_flag)' => ['user_alice' => ['username' => 'alice'], 'user_bob' => ['username' => 'bob']], 'Nelmio\\Entity\\Owner' => ['owner1' => []]];
     $flagParserProphecy = $this->prophesize(FlagParserInterface::class);
     $userFlags = (new FlagBag('Nelmio\\Alice\\Entity\\User'))->withFlag(new ElementFlag('dummy_flag'));
     $flagParserProphecy->parse('Nelmio\\Entity\\User (dummy_flag)')->willReturn($userFlags);
     $ownerFlags = new FlagBag('Nelmio\\Entity\\Owner');
     $flagParserProphecy->parse('Nelmio\\Entity\\Owner')->willReturn(new FlagBag('Nelmio\\Entity\\Owner'));
     /** @var FlagParserInterface $flagParser */
     $flagParser = $flagParserProphecy->reveal();
     $fixtureDenormalizerProphecy = $this->prophesize(FixtureDenormalizerInterface::class);
     $newFixtureBag = new FixtureBag();
     $bag1 = $newFixtureBag->with($fixture1);
     $fixtureDenormalizerProphecy->denormalize(new FixtureBag(), 'Nelmio\\Alice\\Entity\\User', 'user_alice', ['username' => 'alice'], $userFlags)->willReturn($bag1);
     $bag2 = $bag1->with($fixture2);
     $fixtureDenormalizerProphecy->denormalize($bag1, 'Nelmio\\Alice\\Entity\\User', 'user_bob', ['username' => 'bob'], $userFlags)->willReturn($bag2);
     $bag3 = $bag2->with($fixture3);
     $fixtureDenormalizerProphecy->denormalize($bag2, 'Nelmio\\Entity\\Owner', 'owner1', [], $ownerFlags)->willReturn($bag3);
     /** @var FixtureDenormalizerInterface $fixtureDenormalizer */
     $fixtureDenormalizer = $fixtureDenormalizerProphecy->reveal();
     $denormalizer = new SimpleFixtureBagDenormalizer($fixtureDenormalizer, $flagParser);
     $actual = $denormalizer->denormalize($data);
     $this->assertSame($bag3, $actual);
     $flagParserProphecy->parse(Argument::any())->shouldHaveBeenCalledTimes(2);
     $fixtureDenormalizerProphecy->denormalize(Argument::cetera())->shouldHaveBeenCalledTimes(3);
 }