public function testAccessors() { $context = new GenerationContext(); $this->assertTrue($context->isFirstPass()); $this->assertFalse($context->needsCompleteGeneration()); $context->setToSecondPass(); $this->assertFalse($context->isFirstPass()); $this->assertFalse($context->needsCompleteGeneration()); $context->markAsNeedsCompleteGeneration(); $this->assertFalse($context->isFirstPass()); $this->assertTrue($context->needsCompleteGeneration()); $context->unmarkAsNeedsCompleteGeneration(); $this->assertFalse($context->isFirstPass()); $this->assertFalse($context->needsCompleteGeneration()); }
public function provideSets() { (yield 'decorated generator generates a complete object => complete object' => (function () { $fixture = new SimpleFixture('dummy', 'Dummy', SpecificationBagFactory::create(null, (new PropertyBag())->with(new Property('foo', 'bar')))); $context = new GenerationContext(); $decoratedGeneratorProphecy = $this->prophesize(ObjectGeneratorInterface::class); $decoratedGeneratorProphecy->generate(Argument::cetera())->willReturn((new ObjectBag())->with(new CompleteObject(new SimpleObject('dummy', new \stdClass())))); /** @var ObjectGeneratorInterface $decoratedGenerator */ $decoratedGenerator = $decoratedGeneratorProphecy->reveal(); $expected = (new ObjectBag())->with(new CompleteObject(new CompleteObject(new SimpleObject('dummy', new \stdClass())))); return [$fixture, $context, $decoratedGenerator, $expected]; })()); (yield 'object has been generated during the second pass => complete object' => (function () { $fixture = new SimpleFixture('dummy', 'Dummy', SpecificationBagFactory::create(null, (new PropertyBag())->with(new Property('foo', 'bar')))); $context = new GenerationContext(); $context->setToSecondPass(); $decoratedGeneratorProphecy = $this->prophesize(ObjectGeneratorInterface::class); $decoratedGeneratorProphecy->generate(Argument::cetera())->willReturn((new ObjectBag())->with(new SimpleObject('dummy', new \stdClass()))); /** @var ObjectGeneratorInterface $decoratedGenerator */ $decoratedGenerator = $decoratedGeneratorProphecy->reveal(); $expected = (new ObjectBag())->with(new CompleteObject(new SimpleObject('dummy', new \stdClass()))); return [$fixture, $context, $decoratedGenerator, $expected]; })()); (yield 'object was generated with "complete object" generation context => complete object' => (function () { $fixture = new SimpleFixture('dummy', 'Dummy', SpecificationBagFactory::create(null, (new PropertyBag())->with(new Property('foo', 'bar')))); $context = new GenerationContext(); $context->markAsNeedsCompleteGeneration(); $decoratedGeneratorProphecy = $this->prophesize(ObjectGeneratorInterface::class); $decoratedGeneratorProphecy->generate(Argument::cetera())->willReturn((new ObjectBag())->with(new SimpleObject('dummy', new \stdClass()))); /** @var ObjectGeneratorInterface $decoratedGenerator */ $decoratedGenerator = $decoratedGeneratorProphecy->reveal(); $expected = (new ObjectBag())->with(new CompleteObject(new SimpleObject('dummy', new \stdClass()))); return [$fixture, $context, $decoratedGenerator, $expected]; })()); (yield 'object generated needed only instantiation => complete object' => (function () { $fixture = new SimpleFixture('dummy', 'Dummy', SpecificationBagFactory::create()); $context = new GenerationContext(); $decoratedGeneratorProphecy = $this->prophesize(ObjectGeneratorInterface::class); $decoratedGeneratorProphecy->generate(Argument::cetera())->willReturn((new ObjectBag())->with(new SimpleObject('dummy', new \stdClass()))); /** @var ObjectGeneratorInterface $decoratedGenerator */ $decoratedGenerator = $decoratedGeneratorProphecy->reveal(); $expected = (new ObjectBag())->with(new CompleteObject(new SimpleObject('dummy', new \stdClass()))); return [$fixture, $context, $decoratedGenerator, $expected]; })()); (yield 'object generated during first pass => unchanged' => (function () { $fixture = new SimpleFixture('dummy', 'Dummy', SpecificationBagFactory::create(null, (new PropertyBag())->with(new Property('foo', 'bar')))); $context = new GenerationContext(); $decoratedGeneratorProphecy = $this->prophesize(ObjectGeneratorInterface::class); $decoratedGeneratorProphecy->generate(Argument::cetera())->willReturn($expected = (new ObjectBag())->with(new SimpleObject('dummy', new \stdClass()))); /** @var ObjectGeneratorInterface $decoratedGenerator */ $decoratedGenerator = $decoratedGeneratorProphecy->reveal(); return [$fixture, $context, $decoratedGenerator, $expected]; })()); }