friends-of-behat/variadic-extension

为 behat 上下文参数提供可变参数支持

安装次数: 4,254,012

依赖: 464

建议: 0

安全性: 0

星标: 226

关注者: 6

分支: 7

开放问题: 1

语言:Gherkin

v1.6.0 2024-01-30 11:13 UTC

This package is auto-updated.

Last update: 2024-08-30 01:09:00 UTC


README

为 Behat 步骤定义添加可变参数支持。

用法

  1. 安装它

    $ composer require friends-of-behat/variadic-extension --dev
  2. 在 Behat 配置中启用它

    # behat.yml
    default:
        # ...
        extensions:
            FriendsOfBehat\VariadicExtension: ~
  3. 您可以在步骤定义中使用可变参数!

    /**
     * @Given the store has( also) :firstProductName and :secondProductName products
     * @Given the store has( also) :firstProductName, :secondProductName and :thirdProductName products
     * @Given the store has( also) :firstProductName, :secondProductName, :thirdProductName and :fourthProductName products
     */
    public function theStoreHasProducts(...$productsNames)
    {
        foreach ($productsNames as $productName) {
            $this->saveProduct($this->createProduct($productName));
        }
    }
    
    /**
     * @Given /^(this channel) has "([^"]+)", "([^"]+)", "([^"]+)" and "([^"]+)" products$/
     */
    public function thisChannelHasProducts(ChannelInterface $channel, ...$productsNames)
    {
        foreach ($productsNames as $productName) {
            $product = $this->createProduct($productName, 0, $channel);
    
            $this->saveProduct($product);
        }
    }