22
33Adds variadic arguments support to Behat steps definitions.
44
5+ ## The why
6+
7+ In Behat, if you want a step definition to accept different numbers of arguments, you normally have to define separate methods for each variation.
8+ This quickly becomes repetitive and hard to maintain as the number of argument combinations grows.
9+
10+ This extension solves that by letting you use PHP's variadic syntax (` ...$args ` ) in your step definitions.
11+ A single method can capture many argument variations, keeping your context classes clean and concise.
12+
513## Usage
614
7151 . Install it:
8-
16+
917 ``` bash
1018 $ composer require friends-of-behat/variadic-extension --dev
1119 ```
1220
13212. Enable it in your Behat configuration:
14-
22+
1523 ` ` ` yaml
1624 # behat.yml
1725 default:
@@ -20,6 +28,22 @@ Adds variadic arguments support to Behat steps definitions.
2028 FriendsOfBehat\V ariadicExtension: ~
2129 ` ` `
2230
31+ or if you use a PHP-based configuration:
32+
33+ ` ` ` php
34+ # behat.php
35+ use Behat\C onfig\C onfig;
36+ use Behat\C onfig\E xtension;
37+ use Behat\C onfig\P rofile;
38+ use FriendsOfBehat\V ariadicExtension\S erviceContainer\V ariadicExtension;
39+
40+ return (new Config ())
41+ -> withProfile(
42+ (new Profile(' default' ))
43+ -> withExtension(new Extension(VariadicExtension::class))
44+ );
45+ ` ` `
46+
23473. You can use variadic arguments in steps definitions!
2448
2549 ` ` ` php
@@ -36,6 +60,8 @@ Adds variadic arguments support to Behat steps definitions.
3660 }
3761
3862 /**
63+ * @Given /^(this channel) has " ([^" ]+)" and " ([^" ]+)" products$/
64+ * @Given /^(this channel) has " ([^" ]+)" , " ([^" ]+)" and " ([^" ]+)" products$/
3965 * @Given /^(this channel) has " ([^" ]+)" , " ([^" ]+)" , " ([^" ]+)" and " ([^" ]+)" products$/
4066 */
4167 public function thisChannelHasProducts(ChannelInterface $channel , ...$productsNames )
0 commit comments