with() public method

Creates a new instance which will have the given fixture. If a fixture of that id already existed, it will be overridden.
public with ( Nelmio\Alice\FixtureInterface $fixture ) : self
$fixture Nelmio\Alice\FixtureInterface
return self
Exemplo n.º 1
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.º 2
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);
 }