/**
  * @inheritdoc
  */
 public function process(ParserInterface $parser, string $file, array $data) : array
 {
     if (false === array_key_exists('include', $data)) {
         throw InvalidArgumentExceptionFactory::createForNoIncludeStatementInData($file);
     }
     $include = $data['include'];
     unset($data['include']);
     if (null === $include) {
         return $data;
     }
     if (false === is_array($include)) {
         throw TypeErrorFactory::createForInvalidIncludeStatementInData($include, $file);
     }
     foreach ($include as $includeFile) {
         if (false === is_string($includeFile)) {
             throw TypeErrorFactory::createForInvalidIncludedFilesInData($includeFile, $file);
         }
         if (0 === strlen($includeFile)) {
             throw InvalidArgumentExceptionFactory::createForEmptyIncludedFileInData($file);
         }
         $filePathToInclude = $this->fileLocator->locate($includeFile, dirname($file));
         $fileToIncludeData = $parser->parse($filePathToInclude);
         if (array_key_exists('include', $fileToIncludeData)) {
             $fileToIncludeData = $this->process($parser, $file, $fileToIncludeData);
         }
         $data = $this->dataMerger->mergeInclude($data, $fileToIncludeData);
     }
     return $data;
 }
Beispiel #2
0
 /**
  * @param string|ValueInterface $parameterKey e.g. 'dummy_param'
  */
 public function __construct($parameterKey)
 {
     if (false === is_string($parameterKey) && false === $parameterKey instanceof ValueInterface) {
         throw TypeErrorFactory::createForInvalidParameterKey($parameterKey);
     }
     $this->parameterKey = $parameterKey;
 }
Beispiel #3
0
 /**
  * @param string  $reference
  * @param object $instance
  */
 public function __construct(string $reference, $instance)
 {
     if (false === is_object($instance)) {
         throw TypeErrorFactory::createForObjectArgument($instance);
     }
     $this->reference = $reference;
     $this->instance = $instance;
 }
 /**
  * {@inheritdoc}
  *
  * @param array $data Full set of parsed data, will look for the parameter subset itself.
  */
 public function denormalize(array $data) : ParameterBag
 {
     if (false === array_key_exists('parameters', $data) || null === ($fixturesParameters = $data['parameters'])) {
         return new ParameterBag();
     }
     if (false === is_array($fixturesParameters)) {
         throw TypeErrorFactory::createForInvalidFixtureBagParameters($fixturesParameters);
     }
     return new ParameterBag($fixturesParameters);
 }
Beispiel #5
0
 /**
  * {@inheritDoc}
  *
  * @param string $file Local PHP file
  */
 public function parse(string $file) : array
 {
     if (false === file_exists($file)) {
         throw InvalidArgumentExceptionFactory::createForFileCouldNotBeFound($file);
     }
     $data = (include $file);
     if (false === is_array($data)) {
         throw TypeErrorFactory::createForInvalidFixtureFileReturnedData($file);
     }
     return $data;
 }
 /**
  * @param ChainableParameterResolverInterface[] $resolvers
  */
 public function __construct(array $resolvers)
 {
     foreach ($resolvers as $index => $resolver) {
         if (false === $resolver instanceof ChainableParameterResolverInterface) {
             throw TypeErrorFactory::createForInvalidChainableParameterResolver($resolver);
         }
         if ($resolver instanceof ParameterResolverAwareInterface) {
             $resolvers[$index] = $resolver->withResolver($this);
         }
     }
     $this->resolvers = $resolvers;
 }
Beispiel #7
0
 /**
  * @param int|ValueInterface    $quantifier
  * @param string|ValueInterface $element
  */
 public function __construct($quantifier, $element)
 {
     if ($quantifier instanceof ValueInterface) {
         $quantifier = clone $quantifier;
     } elseif (false === is_int($quantifier)) {
         throw TypeErrorFactory::createForDynamicArrayQuantifier($quantifier);
     }
     if (false === is_string($element) && false === is_array($element) && false === $element instanceof ValueInterface) {
         throw TypeErrorFactory::createForDynamicArrayElement($element);
     }
     $this->quantifier = $quantifier;
     $this->element = deep_clone($element);
 }
 /**
  * @param FlagParserInterface                     $flagParser
  * @param ChainableFixtureDenormalizerInterface[] $denormalizers
  */
 public function __construct(FlagParserInterface $flagParser, array $denormalizers)
 {
     foreach ($denormalizers as $index => $denormalizer) {
         if (false === $denormalizer instanceof ChainableFixtureDenormalizerInterface) {
             throw TypeErrorFactory::createForInvalidDenormalizerType($index, $denormalizer);
         }
         if ($denormalizer instanceof FixtureDenormalizerAwareInterface) {
             $denormalizer = $denormalizer->withFixtureDenormalizer($this);
         }
         if ($denormalizer instanceof FlagParserAwareInterface) {
             $denormalizer = $denormalizer->withFlagParser($flagParser);
         }
         $this->denormalizers[] = $denormalizer;
     }
 }
Beispiel #9
0
 /**
  * @param int|ValueInterface         $quantifier
  * @param string|ValueInterface      $firstMember
  * @param string|ValueInterface|null $secondMember
  */
 public function __construct($quantifier, $firstMember, $secondMember = null)
 {
     if ($quantifier instanceof ValueInterface) {
         $quantifier = clone $quantifier;
     } elseif (is_scalar($quantifier)) {
         $quantifier = (int) $quantifier;
     } else {
         throw TypeErrorFactory::createForOptionalValueQuantifier($quantifier);
     }
     if (false === is_string($firstMember) && false === $firstMember instanceof ValueInterface) {
         throw TypeErrorFactory::createForOptionalValueFirstMember($firstMember);
     }
     if (null !== $secondMember && false === is_string($secondMember) && false === $secondMember instanceof ValueInterface) {
         throw TypeErrorFactory::createForOptionalValueSecondMember($secondMember);
     }
     $this->quantifier = $quantifier;
     $this->firstMember = $firstMember;
     $this->secondMember = $secondMember;
 }
 private function denormalizeCallMethod(CallsDenormalizerInterface $callsDenormalizer, $methodCall, FixtureInterface $scope, FlagParserInterface $parser) : MethodCallInterface
 {
     if (false === is_array($methodCall)) {
         throw TypeErrorFactory::createForInvalidSpecificationBagMethodCall($methodCall);
     }
     $unparsedMethod = key($methodCall);
     if (false === is_string($unparsedMethod)) {
         throw TypeErrorFactory::createForInvalidSpecificationBagMethodCallName($unparsedMethod);
     }
     return $callsDenormalizer->denormalize($scope, $parser, $unparsedMethod, $methodCall[$unparsedMethod]);
 }