From a16356d296370e7e3c834bad615cfc4b3b60b3f5 Mon Sep 17 00:00:00 2001 From: Jan Goralski Date: Mon, 23 Mar 2026 13:12:45 +0100 Subject: [PATCH] [Maintenance] Update readme --- README.md | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4a6f5bb..2a2728d 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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 @@ -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)