/** * 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(); }
/** * 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); }
/** * Checks if provided transformation is applicable pattern transformation. * * @param DefinitionCall $definitionCall * @param Transformation|string $transformation * @param mixed $value * @param array $match * * @return Boolean */ private function isApplicablePatternTransformation(DefinitionCall $definitionCall, Transformation $transformation, $value, &$match) { $regex = $this->getRegex($definitionCall->getEnvironment()->getSuite()->getName(), $transformation->getPattern(), $definitionCall->getFeature()->getLanguage()); if (is_string($value) && preg_match($regex, $value, $match)) { // take arguments from capture groups if there are some if (count($match) > 1) { $match = array_slice($match, 1); } return true; } return false; }