예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function transformArgument(DefinitionCall $definitionCall, $argumentIndex, $argumentValue)
 {
     $environment = $definitionCall->getEnvironment();
     list($simpleTransformations, $normalTransformations) = $this->splitSimpleAndNormalTransformations($this->repository->getEnvironmentTransformations($environment));
     $newValue = $this->applySimpleTransformations($simpleTransformations, $definitionCall, $argumentIndex, $argumentValue);
     $newValue = $this->applyNormalTransformations($normalTransformations, $definitionCall, $argumentIndex, $newValue);
     return $newValue;
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function transformArgument(CallCenter $callCenter, DefinitionCall $definitionCall, $argumentIndex, $argumentValue)
 {
     $call = new TransformationCall($definitionCall->getEnvironment(), $definitionCall->getCallee(), $this, array($argumentValue));
     $result = $callCenter->makeCall($call);
     if ($result->hasException()) {
         throw $result->getException();
     }
     return $result->getReturn();
 }
 /**
  * {@inheritdoc}
  */
 public function transformArgument(DefinitionCall $definitionCall, $argumentIndex, $argumentValue)
 {
     $environment = $definitionCall->getEnvironment();
     $transformations = $this->repository->getEnvironmentTransformations($environment);
     $newValue = $argumentValue;
     foreach ($transformations as $transformation) {
         $newValue = $this->transform($definitionCall, $transformation, $argumentIndex, $newValue);
     }
     return $newValue;
 }
예제 #4
0
 /**
  * Transforms argument value using transformation and returns a new one.
  *
  * @param RegexGenerator $regexGenerator
  * @param CallCenter     $callCenter
  * @param DefinitionCall $definitionCall
  * @param mixed          $argumentValue
  *
  * @return mixed
  *
  * @throws Exception If transformation throws exception
  */
 public function transformArgument(RegexGenerator $regexGenerator, CallCenter $callCenter, DefinitionCall $definitionCall, $argumentValue)
 {
     $regex = $regexGenerator->generateRegex($definitionCall->getEnvironment()->getSuite()->getName(), $this->pattern, $definitionCall->getFeature()->getLanguage());
     $this->match($regex, $argumentValue, $arguments);
     $call = new TransformationCall($definitionCall->getEnvironment(), $definitionCall->getCallee(), $this, $arguments);
     $result = $callCenter->makeCall($call);
     if ($result->hasException()) {
         throw $result->getException();
     }
     return $result->getReturn();
 }
 public function transformArgument(DefinitionCall $definitionCall, $argumentIndex, $argumentValue)
 {
     /** @var InitializedContextEnvironment $environment */
     $environment = $definitionCall->getEnvironment();
     $class = $this->getParameter($definitionCall->getCallee()->getReflection(), $argumentIndex)->getClass();
     foreach ($environment->getContexts() as $context) {
         if ($class->isInstance($context)) {
             return $context;
         }
     }
     return $argumentValue;
 }
예제 #6
0
 /**
  * {@inheritdoc}
  */
 public function transformArgument(DefinitionCall $definitionCall, $argumentIndex, $argumentValue)
 {
     $environment = $definitionCall->getEnvironment();
     $transformations = $this->repository->getEnvironmentTransformations($environment);
     usort($transformations, function (Transformation $t1, Transformation $t2) {
         // TODO: remove with upgrade of Transformation interface
         $t1p = $t1 instanceof SimpleArgumentTransformation ? $t1->getPriority() : 0;
         $t2p = $t2 instanceof SimpleArgumentTransformation ? $t2->getPriority() : 0;
         if ($t1p == $t2p) {
             return 0;
         }
         return $t1p > $t2p ? -1 : 1;
     });
     $newValue = $argumentValue;
     foreach ($transformations as $transformation) {
         $newValue = $this->transform($definitionCall, $transformation, $argumentIndex, $newValue);
     }
     return $newValue;
 }
 /**
  * Checks if argument is a string and matches pattern.
  *
  * @param DefinitionCall $definitionCall
  * @param mixed          $argumentValue
  * @param string         $pattern
  * @param array          $match
  *
  * @return Boolean
  */
 private function isStringAndMatchesPattern(DefinitionCall $definitionCall, $argumentValue, $pattern, &$match)
 {
     $regex = $this->getRegex($definitionCall->getEnvironment()->getSuite()->getName(), $pattern, $definitionCall->getFeature()->getLanguage());
     return is_string($argumentValue) && preg_match($regex, $argumentValue, $match);
 }
예제 #8
0
 /**
  * Extracts parameters from provided definition call.
  *
  * @param DefinitionCall $definitionCall
  *
  * @return ReflectionParameter[]
  */
 private function getCallParameters(DefinitionCall $definitionCall)
 {
     return $definitionCall->getCallee()->getReflection()->getParameters();
 }
 /**
  * Executes transformation.
  *
  * @param DefinitionCall $definitionCall
  * @param Transformation $transformation
  * @param array          $arguments
  *
  * @return mixed
  *
  * @throws Exception If transformation call throws one
  */
 private function execute(DefinitionCall $definitionCall, Transformation $transformation, array $arguments)
 {
     $call = new TransformationCall($definitionCall->getEnvironment(), $definitionCall->getCallee(), $transformation, $arguments);
     $result = $this->callCenter->makeCall($call);
     if ($result->hasException()) {
         throw $result->getException();
     }
     return $result->getReturn();
 }