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

resolve() public method

public resolve ( Nelmio\Alice\Definition\ValueInterface $list, Nelmio\Alice\FixtureInterface $fixture, ResolvedFixtureSet $fixtureSet, array $scope, GenerationContext $context ) : ResolvedValueWithFixtureSet
$list 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 $list, FixtureInterface $fixture, ResolvedFixtureSet $fixtureSet, array $scope, GenerationContext $context) : ResolvedValueWithFixtureSet
    {
        if (null === $this->resolver) {
            throw ResolverNotFoundExceptionFactory::createUnexpectedCall(__METHOD__);
        }
        $values = $list->getValue();
        foreach ($values as $index => $value) {
            if ($value instanceof ValueInterface) {
                $resolvedSet = $this->resolver->resolve($value, $fixture, $fixtureSet, $scope, $context);
                $values[$index] = $resolvedSet->getValue();
                $fixtureSet = $resolvedSet->getSet();
            }
        }
        return new ResolvedValueWithFixtureSet(implode('', $values), $fixtureSet);
    }

Usage Example

Beispiel #1
0
 public function testResolvesAllTheValuesInArrayBeforeImplodingIt()
 {
     $value = new ListValue(['a', new FakeValue(), 'c', new FakeValue()]);
     $fixture = new FakeFixture();
     $set = ResolvedFixtureSetFactory::create(new ParameterBag(['foo' => 'bar']));
     $scope = ['scope' => 'epocs'];
     $context = new GenerationContext();
     $context->markIsResolvingFixture('foo');
     $valueResolverProphecy = $this->prophesize(ValueResolverInterface::class);
     $valueResolverProphecy->resolve(new FakeValue(), $fixture, $set, $scope, $context)->willReturn(new ResolvedValueWithFixtureSet('b', $newSet = ResolvedFixtureSetFactory::create(new ParameterBag(['foo' => 'baz']))));
     $valueResolverProphecy->resolve(new FakeValue(), $fixture, $newSet, $scope, $context)->willReturn(new ResolvedValueWithFixtureSet('d', $newSet2 = ResolvedFixtureSetFactory::create(new ParameterBag(['foo' => 'zab']))));
     /** @var ValueResolverInterface $valueResolver */
     $valueResolver = $valueResolverProphecy->reveal();
     $expected = new ResolvedValueWithFixtureSet('abcd', $newSet2);
     $resolver = new ListValueResolver($valueResolver);
     $actual = $resolver->resolve($value, $fixture, $set, $scope, $context);
     $this->assertEquals($expected, $actual);
     $valueResolverProphecy->resolve(Argument::cetera())->shouldHaveBeenCalledTimes(2);
 }