Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add support for table transforms. Ensure last defined transform wins,…

… and stop transforming when one works.
  • Loading branch information...
commit b0f1ce1b730a91efcd2aae24ad931370fc696357 1 parent 0ac6cc0
Kevin Olbrich authored
View
22 features/step_definitions/WireSteps.php
@@ -175,6 +175,20 @@ public function stepGettingParameterShouldRaiseAnParameter($sKey, $sExceptionCla
public function transformToInteger($sArg) {
return intval($sArg);
}
+
+ /**
+ * Transform /^(abcd)$/
+ **/
+ public function transformReverse($sArg) {
+ return "dcba";
+ }
+
+ /**
+ * Transform /^(abcd)$/
+ **/
+ public function transformCapitalize($sArg) {
+ return "ABCD";
+ }
/**
* Transform /^\{(.*)\}$/
@@ -182,6 +196,14 @@ public function transformToInteger($sArg) {
public function transformSubstituteValues($sArg) {
return $this->$sArg;
}
+
+ /**
+ * Transform /^table:reverse$/
+ **/
+ public function transformReverseTable($aTable) {
+ return array_reverse($aTable);
+ }
+
/**
* Then /^"([^"]*)" should be a kind of "([^"]*)"$/
View
18 features/transform.feature
@@ -7,4 +7,20 @@ Scenario: An argument is transformed to an integer
Scenario: use a transform to substitute variable in arguments
Given I store "foo" into "Bar"
And I store "{Bar}" into "Foo"
- Then "Foo" should equal "foo"
+ Then "Foo" should equal "foo"
+
+Scenario: An argument is transformed to an integer, but the second defined transform wins
+ Given I store "abcd" into "Foo"
+ Then "Foo" should equal "ABCD"
+
+Scenario: transform a table
+ Given "table" is:
+ | reverse |
+ | one |
+ | two |
+ | three |
+ Then "table" should equal:
+ | reverse |
+ | three |
+ | two |
+ | one |
View
18 lib/CucumberScenario.php
@@ -112,14 +112,24 @@ function invokeAfterHooks($aTags) {
function invoke($iStepId, $aArgs) {
$aStep = $this->aWorld['steps'][$iStepId];
$oStep = new $aStep['class']($this->aGlobals);
- foreach ($aArgs as $iIndex => $sArg) {
- foreach ($this->aWorld['transform'] as $aTransform) {
+ foreach ($aArgs as &$sArg) {
+ $sArgTest = $sArg;
+ if (is_array($sArgTest)) {
+ $sArgTest = "table:" . implode(",",$sArgTest[0]);
+ }
+ foreach (array_reverse($this->aWorld['transform'],true) as $aTransform) {
$aMatches = array();
- if (is_string($sArg) && preg_match_all($aTransform['regexp'], $sArg, $aMatches, PREG_OFFSET_CAPTURE)) {
+ if (preg_match_all($aTransform['regexp'], $sArgTest, $aMatches, PREG_OFFSET_CAPTURE)) {
$oTransform = new $aTransform['class']($this->aGlobals);
- $aArgs[$iIndex] = call_user_func_array(array($oTransform, $aTransform['method']),$aMatches[1][0]);
+ if (is_array($sArg)) {
+ $sArg = call_user_func_array(array($oTransform, $aTransform['method']),$sArg);
+ } else {
+ $sArg = call_user_func_array(array($oTransform, $aTransform['method']),$aMatches[1][0]);
+ }
+ break;
}
}
+
}
try {
call_user_func_array(array($oStep, $aStep['method']),$aArgs);
View
1  tests/lib/CucumberScenarioTest.php
@@ -35,6 +35,7 @@ class CucumberScenarioTest extends PHPUnit_Framework_TestCase {
public function setup() {
CucumberSteps::clearMocks();
$this->aWorld = array(
+ 'transform' => array(),
'before' => array(
array(
'tags' => array('one'),
Please sign in to comment.
Something went wrong with that request. Please try again.