homeapp / codeception-config-module
从配置文件中加载参数到Codeception场景。
1.0.0
2023-05-31 09:20 UTC
Requires
- php: >=5.4.0
Requires (Dev)
- codeception/codeception: ^2.2
- phpunit/phpunit: ^4.8
- squizlabs/php_codesniffer: ^2.7
Replaces
This package is auto-updated.
Last update: 2024-08-30 01:44:13 UTC
README
从Codeception配置中加载参数并传递给测试场景。
安装
将包添加到您的composer.json文件中
{ "require-dev": { "codeception/codeception": "^2.2", "justblackbird/codeception-config-module": "^1.0" } }
更新依赖关系以下载包
php composer.phar update
然后,在您的acceptance.suite.yml
配置文件中启用模块,并将任何您想要传递给测试场景的配置
class_name: AcceptanceTester modules: enabled: - Config: # You can use any configs in the list. There no limitations on # the parameters names. foo: 'Foo value' bar: 'Bar value' cookies_price: '$3.50' - PhpBrowser: url: 'https://example.com/' - \Helper\Acceptance
您还需要重新构建您的actor类
php codecept.phar build
使用方法
首先,您需要在Codeception配置中指定您想要传递给测试场景的参数。假设我们需要使用username
和password
来测试登录过程。acceptance.suite.yml
文件可能看起来像这样
class_name: AcceptanceTester modules: enabled: - Config: username: 'john_doe' password: 'foobarbaz123' - PhpBrowser: url: 'https://example.com/' - \Helper\Acceptance
在您设置了配置文件中的参数后,您可以在接受场景中使用它们。以下是一个示例
<?php $I = new AcceptanceTester($scenarion); $I->fillField('Username', $I->grabFromConfig('username')); $I->fillField('Password', $I->grabFromConfig('password')); $I->click('Log in'); $I->see('You\'ve just logged in!');
API
grabFromConfig($parameter)
从模块配置中检索指定的参数。如果未指定参数,则抛出异常。
许可证
MIT (c) Dmitriy Simushev