定制 yceruto/behat-extension 二次开发

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

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

yceruto/behat-extension

最新稳定版本:v1.0.2

Composer 安装命令:

composer require yceruto/behat-extension

包简介

Set of Behat extensions

README 文档

README

Set of Behat extensions to write better Behat tests.

Exception Extension

This extension provides a way to catch exceptions thrown by your behaviors and check them in your tests.

Installation

composer require --dev yceruto/behat-extension

Configuration

Enable the extension in your behat.yml:

default:
    extensions:
        Yceruto\BehatExtension\Extension\ExceptionExtension: ~

Usage

Once the extension is enabled, you can use the (!) mark in any scenario title to indicate that all exceptions thrown in this scenario must be caught. By using some predefined Behat steps included in this package, you can then check the exception class and message.

Example:

Feature: Manage blog posts
  As a blog owner
  I want to manage my blog posts
  So I can keep my blog up to date

  Scenario: Edit a blog post with invalid date
    Given I get a blog post with id "1"
    And I set a published date "3024-01-01"
    Then an exception should be thrown with message "The published date must be in the past."

Note

Note that the (!) mark is mandatory to catch exceptions. If you don't use it, the exception will be thrown as usual.

These predefined steps can be found in the ExceptionAssertionTrait, which are activated once you add it to your Behat context class. Alternatively, you can create custom Behat steps and use the ExceptionAssertion class directly.

This is a sample of the FeatureContext class that implements the previous feature:

class FeatureContext implements Context
{
    use ExceptionAssertionTrait;

    /**
     * @Given I get a blog post with id :id
     */
    public function iGetABlogPostWithId(int $id): void
    {
        // code that gets the blog post...
    }

    /**
     * @Given I set a published date :date
     */
    public function iSetAPublishedDate(string $date): void
    {
        // code that throws an exception...
    
        throw new DomainException('The published date must be in the past.');
    }
}

License

This software is published under the MIT License

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-06-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固