Inheritance: implements IteratorAggregate, implements Countable
Esempio n. 1
0
 public function __construct(FixtureInterface $fixture, FlagBag $flags)
 {
     if ($fixture->getId() !== $flags->getKey()) {
         throw InvalidArgumentExceptionFactory::createForFlagBagKeyMismatch($fixture, $flags);
     }
     $this->fixture = clone $fixture;
     $this->flags = $flags;
 }
Esempio n. 2
0
 public function testAddingAFlagCreatesANewModifiedInstance()
 {
     $flag = new MutableFlag('flag0', new \stdClass());
     $bag1 = new FlagBag('user0');
     $bag2 = $bag1->withFlag($flag);
     $this->assertInstanceOf(FlagBag::class, $bag1);
     $this->assertNotSame($bag1, $bag2);
     $this->assertCount(0, $bag1);
     $this->assertCount(1, $bag2);
     // Mutate injected value
     $flag->setStringValue('flag1');
     $flag->getObject()->injected = true;
     // Mutate return value
     foreach ($bag1 as $flag) {
         /** @var MutableFlag $flag */
         $flag->setStringValue('flag2');
         $flag->getObject()->foo = 'bar';
     }
     $this->assertEquals((new FlagBag('user0'))->withFlag(new MutableFlag('flag0', new \stdClass())), $bag2);
 }
Esempio n. 3
0
 /**
  * @param FixtureInterface     $scope
  * @param FlagBag              $flags
  * @param mixed|ValueInterface $value
  *
  * @throws InvalidScopeException
  *
  * @return ValueInterface
  */
 private function generateValue(FixtureInterface $scope, FlagBag $flags, $value) : ValueInterface
 {
     $uniqueId = sprintf('%s#%s', $scope->getClassName(), $flags->getKey());
     if ('temporary_id' === substr($scope->getId(), 0, 12)) {
         throw DenormalizerExceptionFactory::createForInvalidScopeForUniqueValue();
     }
     if ($value instanceof DynamicArrayValue) {
         $uniqueId = uniqid($uniqueId . '::', true);
         return new DynamicArrayValue($value->getQuantifier(), new UniqueValue($uniqueId, $value->getElement()));
     }
     if ($value instanceof ArrayValue) {
         $uniqueId = uniqid($uniqueId . '::', true);
         $elements = $value->getValue();
         foreach ($elements as $key => $element) {
             // The key must be the same for each argument: the unique ID is bound to the array, not the argument
             // number.
             $elements[$key] = new UniqueValue($uniqueId, $element);
         }
         return new ArrayValue($elements);
     }
     return new UniqueValue($uniqueId, $value);
 }
 public static function createForFlagBagKeyMismatch(FixtureInterface $fixture, FlagBag $flags) : \InvalidArgumentException
 {
     return new \InvalidArgumentException(sprintf('Expected the fixture ID and the flags key to be the same. Got "%s" and "%s" instead.', $fixture->getId(), $flags->getKey()));
 }
Esempio n. 5
0
 private function createFixtureWithFlags(FlagBag $flags) : SimpleFixtureWithFlags
 {
     return new SimpleFixtureWithFlags(new SimpleFixture($flags->getKey(), 'Dummy', SpecificationBagFactory::create()), $flags);
 }