|
| 1 | +Feature: Using variadic arguments in steps definitions with named parameters |
| 2 | + In order to make Behat steps definitions cleaner and more readable |
| 3 | + As a Behat User |
| 4 | + I want to use 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 | +
|
| 19 | + class FeatureContext implements Context |
| 20 | + { |
| 21 | + /** |
| 22 | + * @When I pass :firstArgument and :secondArgument as arguments |
| 23 | + * @When I pass :firstArgument, :secondArgument and :thirdArgument as arguments |
| 24 | + */ |
| 25 | + public function iPass(...$arguments) |
| 26 | + { |
| 27 | + printf('Number of passed arguments: %d', count($arguments)); |
| 28 | + } |
| 29 | +
|
| 30 | + /** |
| 31 | + * @When I pass :firstArgument and :secondArgument as arguments to :subject |
| 32 | + */ |
| 33 | + public function iPassToSubject($subject, ...$arguments) |
| 34 | + { |
| 35 | + printf('Number of arguments passed to %s: %d', $subject, count($arguments)); |
| 36 | + } |
| 37 | + } |
| 38 | + """ |
| 39 | + |
| 40 | + Scenario: Using two variadic arguments as the only ones |
| 41 | + Given a feature file "features/variadics_arguments_support.feature" containing: |
| 42 | + """ |
| 43 | + Feature: Passing arguments |
| 44 | +
|
| 45 | + Scenario: Passing two arguments |
| 46 | + When I pass "foo" and "bar" as arguments |
| 47 | + """ |
| 48 | + When I run Behat |
| 49 | + Then it should pass with "Number of passed arguments: 2" |
| 50 | + |
| 51 | + Scenario: Using three variadic arguments as the only ones |
| 52 | + Given a feature file "features/variadics_arguments_support.feature" containing: |
| 53 | + """ |
| 54 | + Feature: Passing arguments |
| 55 | +
|
| 56 | + Scenario: Passing three arguments |
| 57 | + When I pass "foo", "bar" and "baz" as arguments |
| 58 | + """ |
| 59 | + When I run Behat |
| 60 | + Then it should pass with "Number of passed arguments: 3" |
| 61 | + |
| 62 | + Scenario: Using variadic arguments together with regular one |
| 63 | + Given a feature file "features/variadics_arguments_support.feature" containing: |
| 64 | + """ |
| 65 | + Feature: Passing two variadic arguments and one regular argument |
| 66 | +
|
| 67 | + Scenario: Passing two variadic arguments and one regular argument |
| 68 | + When I pass "foo" and "bar" as arguments to method |
| 69 | +
|
| 70 | + """ |
| 71 | + When I run Behat |
| 72 | + Then it should pass with "Number of arguments passed to method: 2" |
0 commit comments