rmiller/behat-spec 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

rmiller/behat-spec

Composer 安装命令:

composer require rmiller/behat-spec

包简介

Behat and PhpSpec integration

README 文档

README

Scrutinizer Code Quality Build Status

What

Integration between Behat and PhpSpec.

  • Creates specs for any missing classes encountered when running behat
  • Adds examples for any missing methods encountered when running behat
  • Executes the phpspec run command after this to add the described class/method

Why

This is useful when rather than using the Behat context to run an application through its UI, it is instead used to implement the domain model. For more information on this way of using Gherkin features to drive domain modelling read Everzet's post on Modelling by Example

When running a feature with a Context that contains a new class that does not exist or a method you will get a fatal error. If using PhpSpec the next step would be to start specifying that class using the describe command. This set of extensions provides integration between Behat and PhpSpec so that instead of a fatal error you can choose to run the describe command for the missing class automatically.

It also uses my ExemplifyExtension so that you can automatically add examples for missing methods in a similar way.

After describing a class or method in this way the phpspec run command can be used to automatically create the class or model. Since this is the typical next step in most cases, this extension automates that by asking you if you would like to do that next.

An Example

So to use an example from the blog post linked above:

/**
 * @Given a product named :name and priced £:price was added to the catalogue
 */
public function aProductNamedAndPricedWasAddedToTheCatalogue($name, Money $price)
{
    $aProduct = Product::namedAndPriced($name, $price);
    $this->catalogue->add($aProduct);
}

Running the feature relating to this context would result in a fatal exception normally. Instead you get a simple error and the offer to create a spec for the missing class:

Product not found

The spec is created followed by an offer to run phpspec run:

Spec created

Which asks to create the class:

Created Product?

Product created

Running Behat again will result in a similar process for the namedAndPriced method. Where an example for the method will be added to the spec and the method added to the class.

How

Installation

This package provides an extension for PhpSpec and an extension for Behat. Both need to be enabled for the full functionality.

Requires:

  • Behat 3.0+
  • PhpSpec 3.0+
  • PHP 5.6+

Require the extension:

$ composer require --dev rmiller/behat-spec:^0.5

In order to use BehatSpec with PHPSpec 2.0 series, use 0.3.* version series:

$ composer require --dev rmiller/behat-spec:0.3.*

To get the phpspec run command running, you need to use latest phpspec >2.1. Otherwise that functionality will silently fail.

Configuration

Activate the Behat extension by specifying its class in your behat.yml:

# behat.yml
# ...
extensions:
    RMiller\BehatSpec\Extension\BehatSpecExtension\BehatExtension:
        path:  bin/phpspec #default value is bin/phpspec
        config:  path/to/phpspec.yml #optional

Activate the PhpSpec extension by specifying its class in your phpspec.yml:

# phpspec.yml
extensions:
    RMiller\BehatSpec\Extension\BehatSpecExtension\PhpSpecExtension: ~

Additional configuration can be provided for the running of the phpspec run command:

It defaults to bin/phpspec for the path of phpspec and to run after the describe command. These can be overridden as follows:

# phpspec.yml
rerunner:
    path: vendor/bin/phpspec
    commands: [describe, exemplify, your_own_fancy_command]
    config: path/to/phpspec.yml #optional

extensions:
    RMiller\BehatSpec\Extension\BehatSpecExtension\PhpSpecExtension: ~

Some Details

This package pulls together some other PhpSpec and Behat extensions which can also be used standalone:

PhpSpec

Behat

rmiller/behat-spec 适用场景与选型建议

rmiller/behat-spec 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 21.71k 次下载、GitHub Stars 达 52, 最近一次更新时间为 2014 年 11 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「BDD」 「SpecBDD」 「StoryBDD」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 rmiller/behat-spec 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 rmiller/behat-spec 我们能提供哪些服务?
定制开发 / 二次开发

基于 rmiller/behat-spec 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 21.71k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 53
  • 点击次数: 18
  • 依赖项目数: 9
  • 推荐数: 0

GitHub 信息

  • Stars: 52
  • Watchers: 6
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-11-03