定制 treehouselabs/behat-common 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

treehouselabs/behat-common

最新稳定版本:v0.2.2

Composer 安装命令:

composer require treehouselabs/behat-common

包简介

Common Behat contexts to use in our Symfony projects

README 文档

README

This package is no longer maintained. It is advised to write specific contexts and step definitions, or use better maintained ones. Good starting points are:

Previous readme below 👇

Behat Common

Collection of contexts and traits for writing Behat features in your Symfony projects.

Quick install:

1. Install the package through composer

Just run composer require --dev treehouselabs/behat-common

2. Create a feature context like normal (extending RawMinkContext)

<?php

namespace AppBundle\Behat;

use TreeHouse\BehatCommon\AbstractBaseContext;
use TreeHouse\BehatCommon\CookieTrait;

class FeatureContext extends RawMinkContext
{
    // write your own step definitions here...
}

3. Configure your behat.yml to use these contexts:

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. Write some scenarios:

Using the DoctrineOrmContext and SwiftmailerContext to test a sign-up scenario:

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            |

NOTE: Both DoctrineOrmContext and PDOContext support the use of fakers in your fixtures (see https://github.com/fzaninotto/Faker), like so:

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. Run behat!

bin/behat features/blog.feature

统计信息

  • 总下载量: 87.44k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 9
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-07-15