yceruto/behat-extension 问题修复 & 功能扩展

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

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

yceruto/behat-extension

最新稳定版本:v1.0.1

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

统计信息

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

GitHub 信息

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

其他信息

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