Nelmio\Alice\Generator\Resolver\Value\Chainable\FunctionCallArgumentResolver::resolve PHP Method

resolve() public method

public resolve ( Nelmio\Alice\Definition\ValueInterface $value, Nelmio\Alice\FixtureInterface $fixture, ResolvedFixtureSet $fixtureSet, array $scope, GenerationContext $context ) : ResolvedValueWithFixtureSet
$value Nelmio\Alice\Definition\ValueInterface
$fixture Nelmio\Alice\FixtureInterface
$fixtureSet Nelmio\Alice\Generator\ResolvedFixtureSet
$scope array
$context Nelmio\Alice\Generator\GenerationContext
return Nelmio\Alice\Generator\ResolvedValueWithFixtureSet
    public function resolve(ValueInterface $value, FixtureInterface $fixture, ResolvedFixtureSet $fixtureSet, array $scope, GenerationContext $context) : ResolvedValueWithFixtureSet
    {
        if (null === $this->argumentResolver) {
            throw ResolverNotFoundExceptionFactory::createUnexpectedCall(__METHOD__);
        }
        $arguments = $value->getArguments();
        foreach ($arguments as $index => $argument) {
            if ($argument instanceof ValueInterface) {
                $resolvedSet = $this->argumentResolver->resolve($argument, $fixture, $fixtureSet, $scope, $context);
                $arguments[$index] = $resolvedSet->getValue();
                $fixtureSet = $resolvedSet->getSet();
            }
        }
        return $this->resolver->resolve(new FunctionCallValue($value->getName(), $arguments), $fixture, $fixtureSet, $scope, $context);
    }

Usage Example

 public function testResolvesAllArgumentsValuesBeforePassingThemToTheDecoratedResolver()
 {
     $value = new FunctionCallValue('foo', ['scalar', new FakeValue(), 'another scalar']);
     $fixture = new FakeFixture();
     $set = ResolvedFixtureSetFactory::create(new ParameterBag(['foo' => 'bar']));
     $scope = ['val' => 'scopie'];
     $context = new GenerationContext();
     $context->markIsResolvingFixture('foo');
     $argumentResolverProphecy = $this->prophesize(ValueResolverInterface::class);
     $argumentResolverProphecy->resolve(new FakeValue(), $fixture, $set, $scope, $context)->willReturn(new ResolvedValueWithFixtureSet($instance = new \stdClass(), $newSet = ResolvedFixtureSetFactory::create(new ParameterBag(['ping' => 'pong']))));
     /** @var ValueResolverInterface $argumentResolver */
     $argumentResolver = $argumentResolverProphecy->reveal();
     $decoratedResolverProphecy = $this->prophesize(ValueResolverInterface::class);
     $decoratedResolverProphecy->resolve(new FunctionCallValue('foo', ['scalar', $instance, 'another scalar']), $fixture, $newSet, $scope, $context)->willReturn($expected = new ResolvedValueWithFixtureSet('end', ResolvedFixtureSetFactory::create(new ParameterBag(['gnip' => 'gnop']))));
     /** @var ValueResolverInterface $decoratedResolver */
     $decoratedResolver = $decoratedResolverProphecy->reveal();
     $resolver = new FunctionCallArgumentResolver($decoratedResolver, $argumentResolver);
     $actual = $resolver->resolve($value, $fixture, $set, $scope, $context);
     $this->assertEquals($expected, $actual);
 }