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

resolve() public method

public resolve ( Nelmio\Alice\Definition\ValueInterface $value, Nelmio\Alice\FixtureInterface $fixture, ResolvedFixtureSet $fixtureSet, array $scope, GenerationContext $context, integer $tryCounter ) : ResolvedValueWithFixtureSet
$value Nelmio\Alice\Definition\ValueInterface
$fixture Nelmio\Alice\FixtureInterface
$fixtureSet Nelmio\Alice\Generator\ResolvedFixtureSet
$scope array
$context Nelmio\Alice\Generator\GenerationContext
$tryCounter integer
return Nelmio\Alice\Generator\ResolvedValueWithFixtureSet
    public function resolve(ValueInterface $value, FixtureInterface $fixture, ResolvedFixtureSet $fixtureSet, array $scope, GenerationContext $context, int $tryCounter = 0) : ResolvedValueWithFixtureSet
    {
        $this->checkResolver(__METHOD__);
        $tryCounter = $this->incrementCounter($tryCounter, $value, $this->limit);
        /**
         * @var UniqueValue        $generatedValue
         * @var ResolvedFixtureSet $fixtureSet
         */
        list($generatedValue, $fixtureSet) = $this->generateValue($value, $fixture, $fixtureSet, $scope, $context);
        if ($this->pool->has($generatedValue)) {
            return $this->resolve($value, $fixture, $fixtureSet, $scope, $context, $tryCounter);
        }
        $this->pool->add($generatedValue);
        return new ResolvedValueWithFixtureSet($generatedValue->getValue(), $fixtureSet);
    }

Usage Example

Example #1
0
 public function testThrowsIfLimitForGenerationOfUniqueValuesIsReached()
 {
     $uniqueId = 'uniqid';
     $realValue = new FakeValue();
     $value = new UniqueValue($uniqueId, $realValue);
     $fixture = new FakeFixture();
     $set = ResolvedFixtureSetFactory::create();
     $scope = ['scope' => 'epocs'];
     $context = new GenerationContext();
     $context->markIsResolvingFixture('foo');
     $pool = new UniqueValuesPool();
     $pool->add(new UniqueValue($uniqueId, 10));
     $pool->add(new UniqueValue($uniqueId, 11));
     $decoratedResolverProphecy = $this->prophesize(ValueResolverInterface::class);
     $decoratedResolverProphecy->resolve($realValue, $fixture, $set, $scope, $context)->willReturn(new ResolvedValueWithFixtureSet(10, $set));
     /** @var ValueResolverInterface $decoratedResolver */
     $decoratedResolver = $decoratedResolverProphecy->reveal();
     $resolver = new UniqueValueResolver($pool, $decoratedResolver);
     try {
         $resolver->resolve($value, $fixture, $set, $scope, $context);
         $this->fail('Expected exception to be thrown.');
     } catch (UniqueValueGenerationLimitReachedException $exception) {
         $decoratedResolverProphecy->resolve(Argument::cetera())->shouldHaveBeenCalledTimes(150);
     }
 }