/** * @inheritdoc */ public function denormalize(FixtureBag $builtFixtures, string $className, string $unparsedFixtureId, array $specs, FlagBag $flags) : FixtureBag { if (null === $this->flagParser) { throw FlagParserExceptionFactory::createForExpectedMethodToBeCalledIfHasAParser(__METHOD__); } $idFlags = $this->flagParser->parse($unparsedFixtureId); $fixture = new SimpleFixture($idFlags->getKey(), $className, new SpecificationBag(null, new PropertyBag(), new MethodCallBag())); $fixture = $fixture->withSpecs($this->specsDenormalizer->denormalize($fixture, $this->flagParser, $specs)); return $builtFixtures->with(new TemplatingFixture(new SimpleFixtureWithFlags($fixture, $idFlags->mergeWith($flags)))); }
/** * {@inheritdoc} * * @param array $data subset of PHP data coming from the parser (does not contains any parameters) * * @example * $data = [ * 'Nelmio\Alice\Entity\User' => [ * 'user0' => [ * 'username' => 'bob', * ], * ], * ]; * * @return FixtureBag */ public function denormalize(array $data) : FixtureBag { $fixtures = new FixtureBag(); foreach ($data as $fqcnWithFlags => $rawFixtureSet) { $flags = $this->flagParser->parse($fqcnWithFlags); $fqcn = $flags->getKey(); foreach ($rawFixtureSet as $reference => $specs) { $fixtures = $this->fixtureDenormalizer->denormalize($fixtures, $fqcn, $reference, $specs, $flags); } } return $fixtures; }
/** * @inheritdoc */ public function parse(string $element) : FlagBag { if (1 !== preg_match(self::REGEX, $element, $matches)) { return new FlagBag($element); } $flags = new FlagBag($matches['reference']); $stringFlags = preg_split('/\\s*,\\s*/', $matches['stringFlags']); foreach ($stringFlags as $stringFlag) { $flags = $flags->mergeWith($this->parser->parse(trim($stringFlag))); } return $flags; }
private function denormalizeProperty(PropertyDenormalizerInterface $propertyDenormalizer, FlagParserInterface $flagParser, string $unparsedPropertyName, $value, PropertyBag $properties, FixtureInterface $scope) : PropertyBag { $flags = $flagParser->parse($unparsedPropertyName); $propertyName = $flags->getKey(); $property = $propertyDenormalizer->denormalize($scope, $propertyName, $value, $flags); return $properties->with($property); }
/** * @inheritdoc */ public function denormalize(FixtureInterface $scope, FlagParserInterface $parser, string $unparsedMethod, array $unparsedArguments) : MethodCallInterface { $methodFlags = $parser->parse($unparsedMethod); $method = $methodFlags->getKey(); $arguments = $this->argumentDenormalizer->denormalize($scope, $parser, $unparsedArguments); $methodCall = new SimpleMethodCall($method, $arguments); return $this->handleMethodFlags($methodCall, $methodFlags); }
/** * @inheritdoc */ public function denormalize(FixtureInterface $scope, FlagParserInterface $parser, array $unparsedArguments) : array { $arguments = []; foreach ($unparsedArguments as $unparsedIndex => $argument) { $argumentFlags = is_string($unparsedIndex) ? $parser->parse($unparsedIndex) : null; $arguments[] = $this->valueDenormalizer->denormalize($scope, $argumentFlags, $argument); } return $arguments; }
public function assertCannotParse(string $element) { if ($this->parser instanceof ChainableFlagParserInterface) { $actual = $this->parser->canParse($element); $this->assertFalse($actual); return; } try { $this->parser->parse($element); $this->fail('Expected exception to be thrown.'); } catch (\LogicException $exception) { // expected } }
/** * @inheritdoc */ public function denormalize(FixtureBag $builtFixtures, string $className, string $fixtureId, array $specs, FlagBag $flags) : FixtureBag { if (null === $this->denormalizer) { throw DenormalizerExceptionFactory::createDenormalizerNotFoundUnexpectedCall(__METHOD__); } if (null === $this->parser) { throw FlagParserExceptionFactory::createForExpectedMethodToBeCalledIfHasAParser(__METHOD__); } $flags = $this->parser->parse($fixtureId)->mergeWith($flags, false); $fixtureId = $flags->getKey(); /** * @var FixtureInterface $tempFixture * @var FixtureBag $builtFixtures */ list($tempFixture, $builtFixtures) = $this->denormalizeTemporaryFixture($builtFixtures, $className, $specs, $flags); $fixtureIds = $this->buildIds($fixtureId); foreach ($fixtureIds as $fixtureId => $valueForCurrent) { $builtFixtures = $builtFixtures->with(new TemplatingFixture(new SimpleFixtureWithFlags(new SimpleFixture($fixtureId, $tempFixture->getClassName(), $tempFixture->getSpecs(), (string) $valueForCurrent), $flags->withKey($fixtureId)))); } return $builtFixtures; }
/** * @inheritdoc */ public function denormalize(FixtureBag $builtFixtures, string $className, string $fixtureId, array $specs, FlagBag $flags) : FixtureBag { try { return $this->collectionDenormalizer->denormalize($builtFixtures, $className, $fixtureId, $specs, $flags); } catch (InvalidScopeException $exception) { // Continue to fallback on a more conventional way } if (null === $this->denormalizer) { throw DenormalizerExceptionFactory::createDenormalizerNotFoundUnexpectedCall(__METHOD__); } if (null === $this->parser) { throw FlagParserExceptionFactory::createForExpectedMethodToBeCalledIfHasAParser(__METHOD__); } $flags = $this->parser->parse($fixtureId)->mergeWith($flags, false); $fixtureId = $flags->getKey(); $fixtureIds = $this->buildIds($fixtureId); foreach ($fixtureIds as $fixtureId => $valueForCurrent) { $builtFixtures = $this->denormalizeFixture($builtFixtures, $className, $fixtureId, $specs, $flags, (string) $valueForCurrent); } return $builtFixtures; }