Skip to content
This repository was archived by the owner on Dec 28, 2021. It is now read-only.

Transforms

mrtorrent edited this page Jul 19, 2011 · 2 revisions

Like Cucumber, cuke4php supports Step Argument Transforms

These can be implemented by declaring functions in a step definition file like this:

/**
* Transform /^(\d+)$/
**/
public function transformToInteger($sArg) {
  return intval($sArg);
}

The arguments are parsed with transforms before they are passed to the step definition function. Transforms are scanned in the order they are defined, only one transform will be applied. The function name must start with 'transform' and the comment block must contain a regular expression to match on. The regex capture is passed into the transform as the argument.

This can be used to do some useful substitutions of variables. Using a transform like this...

/**
* Transform /^\$(.*)$/
**/
public function transformSubstituteValues($sArg) {
  return $this->$sArg;
}

/**
* Given /^"([^"]*)" is "([^"]*)"$/
**/
public function stepParameterIsParameter($sValue,$sKey) {
    $this->$sKey = $sValue;
}

One can write steps like:

Given "today" is "Monday"
Then I fill "Today's date" with "$today"

And the value "Monday" will be passed to the second step definition instead of the value "$today".

Clone this wiki locally