generate() публичный Метод

public generate ( Nelmio\Alice\FixtureInterface $fixture, ResolvedFixtureSet $fixtureSet, GenerationContext $context ) : ObjectBag
$fixture Nelmio\Alice\FixtureInterface
$fixtureSet Nelmio\Alice\Generator\ResolvedFixtureSet
$context Nelmio\Alice\Generator\GenerationContext
Результат Nelmio\Alice\ObjectBag
Пример #1
0
 /**
  * @testdox Do a instantiate-hydrate-calls cycle to generate the object described by the fixture.
  */
 public function testGenerate()
 {
     $this->markTestIncomplete('TODO');
     $fixture = new SimpleFixture('dummy', \stdClass::class, SpecificationBagFactory::create());
     $set = ResolvedFixtureSetFactory::create();
     $context = new GenerationContext();
     $context->markIsResolvingFixture('foo');
     $instance = new \stdClass();
     $instantiatedObject = new SimpleObject($fixture->getId(), $instance);
     $instantiatorProphecy = $this->prophesize(InstantiatorInterface::class);
     $instantiatorProphecy->instantiate($fixture, $set, $context)->willReturn($setWithInstantiatedObject = ResolvedFixtureSetFactory::create(null, null, (new ObjectBag())->with($instantiatedObject)));
     /** @var InstantiatorInterface $instantiator */
     $instantiator = $instantiatorProphecy->reveal();
     $hydratedInstance = clone $instance;
     $hydratedInstance->hydrated = true;
     $hydratedObject = new SimpleObject($fixture->getId(), $hydratedInstance);
     $hydratorProphecy = $this->prophesize(HydratorInterface::class);
     $hydratorProphecy->hydrate($instantiatedObject, $setWithInstantiatedObject, $context)->willReturn($setWithHydratedObject = ResolvedFixtureSetFactory::create(null, null, (new ObjectBag())->with($hydratedObject)));
     /** @var HydratorInterface $hydrator */
     $hydrator = $hydratorProphecy->reveal();
     $instanceAfterCalls = clone $hydratedInstance;
     $instanceAfterCalls->calls = true;
     $objectAfterCalls = new SimpleObject($fixture->getId(), $instanceAfterCalls);
     $callerProphecy = $this->prophesize(CallerInterface::class);
     $callerProphecy->doCallsOn($hydratedObject, $setWithHydratedObject)->willReturn($setWithObjectAfterCalls = ResolvedFixtureSetFactory::create(null, null, (new ObjectBag())->with($objectAfterCalls)));
     /** @var CallerInterface $caller */
     $caller = $callerProphecy->reveal();
     $generator = new SimpleObjectGenerator(new FakeValueResolver(), $instantiator, $hydrator, $caller);
     $objects = $generator->generate($fixture, $set, $context);
     $this->assertEquals($setWithObjectAfterCalls->getObjects(), $objects);
     $instantiatorProphecy->instantiate(Argument::cetera())->shouldHaveBeenCalledTimes(1);
     $hydratorProphecy->hydrate(Argument::cetera())->shouldHaveBeenCalledTimes(1);
     $callerProphecy->doCallsOn(Argument::cetera())->shouldHaveBeenCalledTimes(1);
 }