Nelmio\Alice\Generator\Instantiator\InstantiatorResolverTest::testResolvesAllArguments PHP Method

testResolvesAllArguments() public method

    public function testResolvesAllArguments()
    {
        $specs = SpecificationBagFactory::create(new SimpleMethodCall('__construct', [$firstArg = new VariableValue('firstArg'), $secondArg = new VariableValue('secondArg')]));
        $resolvedSpecs = $specs->withConstructor(new SimpleMethodCall('__construct', ['resolvedFirstArg', 'resolvedSecondArg']));
        $fixture = new SimpleFixture('dummy', 'stdClass', $specs);
        $set = ResolvedFixtureSetFactory::create();
        $context = new GenerationContext();
        $context->markIsResolvingFixture('foo');
        $expected = ResolvedFixtureSetFactory::create(null, (new FixtureBag())->with($fixture->withSpecs($resolvedSpecs)), new ObjectBag(['dummy' => new \stdClass()]));
        $resolverProphecy = $this->prophesize(ValueResolverInterface::class);
        $setAfterFirstArgResolution = new ResolvedFixtureSet($set->getParameters(), (new FixtureBag())->with(new DummyFixture('dummy')), $set->getObjects());
        $resolverProphecy->resolve($firstArg, $fixture, $set, [], $context)->willReturn(new ResolvedValueWithFixtureSet('resolvedFirstArg', $setAfterFirstArgResolution));
        $setAfterSecondArgResolution = new ResolvedFixtureSet($setAfterFirstArgResolution->getParameters(), (new FixtureBag())->with(new DummyFixture('another_dummy')), $setAfterFirstArgResolution->getObjects());
        $resolverProphecy->resolve($secondArg, $fixture, $setAfterFirstArgResolution, [], $context)->willReturn(new ResolvedValueWithFixtureSet('resolvedSecondArg', $setAfterSecondArgResolution));
        /** @var ValueResolverInterface $resolver */
        $resolver = $resolverProphecy->reveal();
        $fixtureAfterResolution = $fixture->withSpecs($resolvedSpecs);
        $decoratedInstantiatorProphecy = $this->prophesize(InstantiatorInterface::class);
        $decoratedInstantiatorProphecy->instantiate($fixtureAfterResolution, $setAfterSecondArgResolution, $context)->willReturn($expected);
        /** @var InstantiatorInterface $decoratedInstantiator */
        $decoratedInstantiator = $decoratedInstantiatorProphecy->reveal();
        $instantiator = new InstantiatorResolver($decoratedInstantiator, $resolver);
        $actual = $instantiator->instantiate($fixture, $set, $context);
        $this->assertSame($expected, $actual);
        $resolverProphecy->resolve(Argument::cetera())->shouldHaveBeenCalledTimes(2);
        $decoratedInstantiatorProphecy->instantiate(Argument::cetera())->shouldHaveBeenCalledTimes(1);
    }