承接 vierge-noire/cakephp-behat-suite 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

vierge-noire/cakephp-behat-suite

Composer 安装命令:

composer require vierge-noire/cakephp-behat-suite

包简介

Test suite for behavior driven tests.

README 文档

README

A CakePHP dedicated suite for behavior driven development.

Installation

For CakePHP ^4.0:

composer require --dev vierge-noire/cakephp-behat-suite "^0.2"

For CakePHP ^3.8:

composer require --dev vierge-noire/cakephp-behat-suite "^0.1"

Setup

Copy this file in the main directory of your app, under the name `behat.yml:

#behat.yml
default:
  autoload:
    '': '%paths.base%/tests/Behat'
  suites:
    app:
      paths:
        - '%paths.base%/tests/Behat/features'
      contexts:
        - CakephpBehatSuite\Context\BootstrapContext:
            bootstrap: '%paths.base%/tests/bootstrap.php'
        - Context\AppContext

The behat.yml file is the equivalent to the PHPUnit's phpunit.xml file. %paths.base% points to your main directory.

Once your behat.yml file has been created, run vendor/bin/behat --init to automatically create the folders and Context classes as defined in the config file.

You can define more suites additional to app, for example for your plugins.

IMPORTANT: the CakephpBehatSuite\Context\BootstrapContext should be present in each of your suites. The argument bootstrap: should direct to the bootstrap.php file of your tests.

For each suite, you will have to specify the location of your features under the key path.

The package provides a set of steps defined by CakephpBehatSuite\Context\BootstrapContext.

Run your tests

The command vendor/bin/behat will run your tests as defined in the `behat.yml file.

Fixture factories

The package makes uses of the CakePHP fixture factories plugin. Make sure your factories are baked and working, in order to use the present package.

You will find the package and its documentation here.

The BootstrapContext class

The CakephpBehatSuite\Context\BootstrapContext contains a set of steps, documented below.

The Context will ensure that the test database gets emptied before each scenario.

Example

Feature

This is how an integration on the edit action of your UsersController could be:

Feature: Users edit

  Background:
    Given I create 1 user with id 1
    And I am a user with a UsersGroups.Permissions name Users
    And I log in

  Scenario:
    When I get 'users/edit/1'
    Then the response is OK

# Edit a non existent user
  Scenario:
    When I get 'users/edit/2'
    Then the response triggers an error
    
# Edit an existing user
  Scenario:
    When I post 'users/edit/1' with data:
      | username  | email          |
      | foo       | foo@foo.foo    |
    Then I am redirected to 'users'
    And this user exists:
      | id  | username  | email          |
      | 1   | foo       | foo@foo.foo    |

behat.yml with plugin

This behat file includes a suite for a dummy plugin MyCustomPlugin. For each suite, a Context has been added too.

#behat.yml
default:
  autoload:
    '': '%paths.base%/tests/Behat'
  suites:
    app:
      paths:
        - '%paths.base%/tests/Behat/features'
      contexts:
        - CakephpBehatSuite\Context\BootstrapContext:
            bootstrap: '%paths.base%/tests/bootstrap.php'
        - Context\AppContext
    my-custom-plugin:
      paths:
        - '%paths.base%/plugins/MyCustomPlugin/tests/Behat/features'
      contexts:
        - CakephpBehatSuite\Context\BootstrapContext:
            bootstrap: '%paths.base%/tests/bootstrap.php'
        - Context\TestPluginContext

Use Migrations

Take full advantage of the Phinx migrations in order to maintain the schema of your test DB. This is optional, but highly recommended.

The CakePHP Test Migrator package will assist you in doing this very simply.

License

The CakePHPFixtureFactories plugin is offered under an MIT license.

Copyright 2020 Juan Pablo Ramirez and Nicolas Masson

Licensed under The MIT License Redistributions of files must retain the above copyright notice.

Authors

  • Juan Pablo Ramirez
  • Nicolas Masson

统计信息

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

GitHub 信息

  • Stars: 8
  • Watchers: 2
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-10-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固