|
| 1 | +Feature: Transforming variadic arguments in step definitions |
| 2 | + In order to make Behat steps definitions cleaner and more readable |
| 3 | + As a Behat User |
| 4 | + I want to have transformed variadic arguments in these |
| 5 | + |
| 6 | + Background: |
| 7 | + Given a Behat configuration containing: |
| 8 | + """ |
| 9 | + default: |
| 10 | + extensions: |
| 11 | + FriendsOfBehat\VariadicExtension: ~ |
| 12 | + """ |
| 13 | + And a context file "features/bootstrap/FeatureContext.php" containing: |
| 14 | + """ |
| 15 | + <?php |
| 16 | +
|
| 17 | + use Behat\Behat\Context\Context; |
| 18 | + use Behat\Hook\BeforeScenario; |
| 19 | + use Behat\Step\When; |
| 20 | + use Behat\Transformation\Transform; |
| 21 | +
|
| 22 | + class FeatureContext implements Context |
| 23 | + { |
| 24 | + #[Transform('/^(\w+)$/')] |
| 25 | + public function transform($string) |
| 26 | + { |
| 27 | + return strtoupper($string); |
| 28 | + } |
| 29 | +
|
| 30 | + #[When('/^I pass "(\w+)" and "(\w+)" as arguments$/')] |
| 31 | + #[When('I pass :firstArgument, :secondArgument and :thirdArgument')] |
| 32 | + public function iPass(...$arguments) |
| 33 | + { |
| 34 | + printf('Arguments: %s', join(', ', $arguments)); |
| 35 | + } |
| 36 | + } |
| 37 | + """ |
| 38 | + |
| 39 | + Scenario: Transforming variadic arguments in step definitions with a regex |
| 40 | + Given a feature file "features/variadic_arguments_support.feature" containing: |
| 41 | + """ |
| 42 | + Feature: Transforming variadic arguments in step definitions |
| 43 | +
|
| 44 | + Scenario: Transforming variadic arguments in step definitions |
| 45 | + When I pass "foo" and "bar" as arguments |
| 46 | + """ |
| 47 | + When I run Behat |
| 48 | + Then it should pass with "Arguments: FOO, BAR" |
| 49 | + |
| 50 | + Scenario: Transforming variadic arguments in step definitions without regex |
| 51 | + Given a feature file "features/variadic_arguments_support.feature" containing: |
| 52 | + """ |
| 53 | + Feature: Transforming variadic arguments in step definitions |
| 54 | +
|
| 55 | + Scenario: Transforming variadic arguments in step definitions |
| 56 | + When I pass "one", "two" and "three" |
| 57 | + """ |
| 58 | + When I run Behat |
| 59 | + Then it should pass with "Arguments: ONE, TWO, THREE" |
0 commit comments