Skip to content

Commit 98b976c

Browse files
Merge pull request #39 from NoResponseMate/maintenance/update-readme
[Maintenance] Update readme
2 parents 784456e + a16356d commit 98b976c

1 file changed

Lines changed: 28 additions & 2 deletions

File tree

README.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,24 @@
22

33
Adds 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

715
1. Install it:
8-
16+
917
```bash
1018
$ composer require friends-of-behat/variadic-extension --dev
1119
```
1220

1321
2. 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\VariadicExtension: ~
2129
```
2230

31+
or if you use a PHP-based configuration:
32+
33+
```php
34+
# behat.php
35+
use Behat\Config\Config;
36+
use Behat\Config\Extension;
37+
use Behat\Config\Profile;
38+
use FriendsOfBehat\VariadicExtension\ServiceContainer\VariadicExtension;
39+
40+
return (new Config())
41+
->withProfile(
42+
(new Profile('default'))
43+
->withExtension(new Extension(VariadicExtension::class))
44+
);
45+
```
46+
2347
3. 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

Comments
 (0)