コード例 #1
0
ファイル: UniqueValueResolver.php プロジェクト: nelmio/alice
 /**
  * {@inheritdoc}
  *
  * @param UniqueValue $value
  *
  * @throws UniqueValueGenerationLimitReachedException
  */
 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);
 }
コード例 #2
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);
     }
 }
コード例 #3
0
ファイル: UniqueValuesPoolTest.php プロジェクト: nelmio/alice
 private function createPoolWithValue($value) : UniqueValuesPool
 {
     $pool = new UniqueValuesPool();
     $pool->add(new UniqueValue('foo', $value));
     return $pool;
 }