Inheritance: implements Nelmio\Alice\Definition\ValueInterface
Example #1
0
 public function add(UniqueValue $value)
 {
     $valueId = $value->getId();
     if (false === array_key_exists($valueId, $this->pool)) {
         $this->pool[$valueId] = [];
     }
     $this->pool[$valueId][] = $value->getValue();
 }
Example #2
0
 public function testImmutableFactories()
 {
     $id = 'Nelmio\\Entity\\User#user0#username';
     $value = new \stdClass();
     $newValue = new \stdClass();
     $newValue->foo = 'bar';
     $original = new UniqueValue($id, $value);
     $clone = $original->withValue($newValue);
     $this->assertInstanceOf(UniqueValue::class, $clone);
     $this->assertEquals($id, $original->getId());
     $this->assertEquals($id, $clone->getId());
     $this->assertEquals($value, $original->getValue());
     $this->assertEquals($newValue, $clone->getValue());
 }
 public static function create(UniqueValue $value, int $limit) : UniqueValueGenerationLimitReachedException
 {
     return new UniqueValueGenerationLimitReachedException(sprintf('Could not generate a unique value after %d attempts for "%s".', $limit, $value->getId()));
 }
Example #4
0
 private function generateValue(UniqueValue $value, FixtureInterface $fixture, ResolvedFixtureSet $fixtureSet, array $scope, GenerationContext $context) : array
 {
     $realValue = $value->getValue();
     if ($realValue instanceof ValueInterface) {
         $result = $this->resolver->resolve($value->getValue(), $fixture, $fixtureSet, $scope, $context);
         return [$value->withValue($result->getValue()), $result->getSet()];
     }
     return [$value, $fixtureSet];
 }
Example #5
0
 public function provideHasValueSet()
 {
     $baseValue = new UniqueValue('foo', 'temporary value');
     // Checks for null
     (yield '[null value] empty' => [new UniqueValuesPool(), $baseValue->withValue(null), false]);
     (yield '[null value] with `null' => [$this->createPoolWithValue(null), $baseValue->withValue(null), true]);
     (yield '[null value] with `false' => [$this->createPoolWithValue(false), $baseValue->withValue(null), false]);
     (yield '[null value] with empty array' => [$this->createPoolWithValue([]), $baseValue->withValue(null), false]);
     (yield '[null value] with empty string' => [$this->createPoolWithValue(''), $baseValue->withValue(null), false]);
     // Full checks for a scalar value
     (yield '[`true`] empty' => [new UniqueValuesPool(), $baseValue->withValue(true), false]);
     (yield '[`true`] with `true`' => [$this->createPoolWithValue(true), $baseValue->withValue(true), true]);
     (yield '[`true`] with `1`' => [$this->createPoolWithValue(1), $baseValue->withValue(true), false]);
     (yield '[`true`] with `-1`' => [$this->createPoolWithValue(-1), $baseValue->withValue(true), false]);
     (yield '[`true`] with `"1"`' => [$this->createPoolWithValue('1'), $baseValue->withValue(true), false]);
     (yield '[`true`] with `"-1"`' => [$this->createPoolWithValue('-1'), $baseValue->withValue(true), false]);
     (yield '[`true`] with `"alice"`' => [$this->createPoolWithValue('alice'), $baseValue->withValue(true), false]);
     // Check objects
     (yield 'with two equivalent objects' => [$this->createPoolWithValue(new \stdClass()), $baseValue->withValue(new \stdClass()), true]);
     (yield 'with two non-equivalent objects' => [$this->createPoolWithValue(new \stdClass()), $baseValue->withValue(StdClassFactory::create(['foo' => 'bar'])), false]);
     (yield 'with two equivalent objects (2)' => [$this->createPoolWithValue(StdClassFactory::create(['relatedDummy' => StdClassFactory::create(['foo' => 'bar'])])), $baseValue->withValue(StdClassFactory::create(['relatedDummy' => StdClassFactory::create(['foo' => 'bar'])])), true]);
     (yield 'with two non-equivalent objects (2)' => [$this->createPoolWithValue(StdClassFactory::create(['relatedDummy' => StdClassFactory::create(['foo' => 'bar'])])), $baseValue->withValue(StdClassFactory::create(['relatedDummy' => StdClassFactory::create(['foo' => new \stdClass()])])), false]);
     // Checks arrays
     (yield 'two identical arrays' => [$this->createPoolWithValue([]), $baseValue->withValue([]), true]);
     (yield 'two equivalent arrays' => [$this->createPoolWithValue([10, 20]), $baseValue->withValue([20, 10]), true]);
     (yield 'two equivalent arrays (2)' => [$this->createPoolWithValue([10, 'foo' => new \stdClass(), 20]), $baseValue->withValue([20, 10, 'foo' => new \stdClass()]), true]);
     (yield 'two non-equivalent arrays (2)' => [$this->createPoolWithValue([10, 20, 30]), $baseValue->withValue([20, 10]), false]);
     (yield 'two non-equivalent arrays (3)' => [$this->createPoolWithValue([1]), $baseValue->withValue([true]), false]);
     (yield 'two non-equivalent arrays (4)' => [$this->createPoolWithValue([10, 'foo' => StdClassFactory::create(['foo' => 'bar']), 20]), $baseValue->withValue([20, 10, 'foo' => new \stdClass()]), false]);
 }