Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@

Adds variadic arguments support to Behat steps definitions.

## The why

In Behat, if you want a step definition to accept different numbers of arguments, you normally have to define separate methods for each variation.
This quickly becomes repetitive and hard to maintain as the number of argument combinations grows.

This extension solves that by letting you use PHP's variadic syntax (`...$args`) in your step definitions.
A single method can capture many argument variations, keeping your context classes clean and concise.

## Usage

1. Install it:

```bash
$ composer require friends-of-behat/variadic-extension --dev
```

2. Enable it in your Behat configuration:

```yaml
# behat.yml
default:
Expand All @@ -20,6 +28,22 @@ Adds variadic arguments support to Behat steps definitions.
FriendsOfBehat\VariadicExtension: ~
```

or if you use a PHP-based configuration:

```php
# behat.php
use Behat\Config\Config;
use Behat\Config\Extension;
use Behat\Config\Profile;
use FriendsOfBehat\VariadicExtension\ServiceContainer\VariadicExtension;

return (new Config())
->withProfile(
(new Profile('default'))
->withExtension(new Extension(VariadicExtension::class))
);
```

3. You can use variadic arguments in steps definitions!

```php
Expand All @@ -36,6 +60,8 @@ Adds variadic arguments support to Behat steps definitions.
}

/**
* @Given /^(this channel) has "([^"]+)" and "([^"]+)" products$/
* @Given /^(this channel) has "([^"]+)", "([^"]+)" and "([^"]+)" products$/
* @Given /^(this channel) has "([^"]+)", "([^"]+)", "([^"]+)" and "([^"]+)" products$/
*/
public function thisChannelHasProducts(ChannelInterface $channel, ...$productsNames)
Expand Down