treehouselabs / behat-common
此包已被废弃,不再维护。未建议替代包。
我们在Symfony项目中使用Behat的通用上下文
v0.2.2
2018-03-02 13:44 UTC
Requires
- php: >=7.0
- behat/behat: ^3.0
- behat/mink: ^1.6
- behat/mink-browserkit-driver: ^1.2
- behat/mink-extension: ^2.0
- behat/symfony2-extension: ^2.0
- doctrine/common: ^2.2
- doctrine/data-fixtures: ^1.1
- doctrine/orm: ^2.2
- phpunit/phpunit: ^5.7|^6.0
- swiftmailer/swiftmailer: ^6.0
- symfony/dependency-injection: ^3.0
- symfony/http-kernel: ^3.0
- symfony/property-access: ^3.0
- symfony/security: ^3.0
This package is auto-updated.
Last update: 2020-02-13 14:43:42 UTC
README
此包不再维护。建议编写特定的上下文和步骤定义,或使用更好的维护版本。好的起点是
以下为之前的README 👇
Behat Common
收集了在Symfony项目中编写Behat功能的上下文和特性。
快速安装
1. 通过composer安装包
只需运行composer require --dev treehouselabs/behat-common
2. 创建一个特征上下文,如常规操作(扩展RawMinkContext
)
<?php namespace AppBundle\Behat; use TreeHouse\BehatCommon\AbstractBaseContext; use TreeHouse\BehatCommon\CookieTrait; class FeatureContext extends RawMinkContext { // write your own step definitions here... }
3. 配置你的behat.yml
以使用这些上下文
default:
# ...
suites:
acme:
# ...
contexts:
- Behat\MinkExtension\Context\MinkContext
- AppBundle\Behat\FeatureContext
# Optionally, you could also include any of the following (and more!)...
- TreeHouse\BehatCommon\CookieContext
- TreeHouse\BehatCommon\FormContext:
field_container_class: my_field_container_class # defaults to 'controls' (symfony default)
- TreeHouse\BehatCommon\MetaContext
- TreeHouse\BehatCommon\SeoContext
- TreeHouse\BehatCommon\SwiftmailerContext
# Since you are using symfony you probably also need to persist some data with doctrine...?
- TreeHouse\BehatCommon\DoctrineOrmContext:
default_prefix: AcmeBundle # defaults to 'AppBundle'
extensions:
Behat\Symfony2Extension: ~
Behat\MinkExtension:
base_url: https://www.acme.dev
sessions:
default:
symfony2: ~
4. 编写一些场景
使用DoctrineOrmContext
和SwiftmailerContext
测试注册场景
Scenario: Register an account When I go to "/sign-up/" And I fill in the following: | registration[email] | foo@example.com | | registration[password] | 1234 | And I select "1" from "registration[date_of_birth][day]" And I select "jan." from "registration[date_of_birth][month]" And I select "1987" from "registration[date_of_birth][year]" # needed to track mails sent (see SwiftmailerContext) And I do not follow redirects And I press "Sign me up!" Then an email with subject "Please confirm your account" should have been sent to "foo@example.com" And the email body should contain "Before you can log-in, you need to confirm your e-mailaddress by clicking on the link below" And I should be redirected to "/login/" And the response status code should be 200 And I should see "Your data has been processed, you should now click on the link in the e-mail we sent you to confirm your e-mailaddress." And the following user should exist: | email | confirmed | profile.date_of_birth | | foo@example.com | 0 | 1987-01-01 |
注意: DoctrineOrmContext
和PDOContext
都支持在固定文件中使用假数据(见https://github.com/fzaninotto/Faker),如下所示
Scenario: Login with a valid email/password combination Given the following users exist: | email | password | confirmed | first_name | last_name | | <email()> | 1234 | 1 | <firstName()> | <lastName()> | # ...
5. 运行behat!
bin/behat features/blog.feature