behat-rest-testing

To help developers to easily understand how to do feature tests with Behat, and to start writing feature tests for REST APIs.

Github星跟蹤圖

Summary

Build Status
Latest Stable Version
Latest Unstable Version
License

This repo is to help developers to easily understand how to do feature tests with Behat, and to start writing feature
tests for REST APIs, with following features included:

  • Core contexts/steps for testing REST APIs.
  • Sample RESTful services, and sample feature tests against the services.
  • Best of all: To start writing feature tests for the project you are working on, you may use this repo in your project
    via Composer if you happen to use Composer to manage 3rd-party libraries.

NOTE: Following instructions focus on Behat 3.0.6+ and PHP 5.4+. If you use Behat 2.x and/or PHP 5.3 (5.3.3+),
please check branch "1.x" for details.

Dependencies

Branch master

Branch 1.x (old releases for Behat 2.x)

Installation - Source

You will need to download Composer and run the install command under the same directory where the 'composer.json'
file is located:

curl -s http://getcomposer.org/installer, php && ./composer.phar install

Installation - Composer

You may also install using Composer if you want to use this repo in your own
project.

Step 1. Add the repo as a dependency.

"require": {
    "deminy/behat-rest-testing": "~3.0.0"
}

NOTE: This is for running with Behat 3 only. If you use Behat 2.x, please check
installation instructions for v1.x for details.

Step 2. Run Composer: php composer.phar install.

How to Test

1. Set up and run REST API server.

You can have a virtual host set up under Apache, with DocumentRoot set to "www/" of this repo and DirectoryIndex set
to "router.php". Please make sure that module mod_rewrite is enabled, otherwise the REST server won't be able to handle
requests properly. You may also need to update option "base_url" in the configuration file "behat.yml".

Alternatively, you may consider to use the
PHP 5.4+ built-in web server.

To start the REST API server using PHP 5.4+ built-in web server, please run command similar to following:

php -S localhost:8081 www/router.php

The web server now serves as the REST API server. You can visit URL http://localhost:8081 to see if the server runs
properly or not (If everything is good, the URL should return string "OK" back).

2. Create the configuration file "behat.yml" (optional).

For the sample test provided, you can create the file by copying directly from file "behat.yml.dist" without any
modifications required.

Note that you don't have to do this if you prefer to use file "behat.yml.dist" directly.

3. Run the test command.

Now, run following command to test sample features:

./vendor/bin/behat
# OR
./vendor/bin/behat -p default # explicitly to use profile "default"

If everything is good, you should see the output as in following screenshot:

output when running Behat sample tests

TODOs

  • Support different environments (development, QA, staging, production, etc).

License

MIT license.

主要指標

概覽
名稱與所有者deminy/behat-rest-testing
主編程語言PHP
編程語言PHP (語言數: 2)
平台
許可證Other
所有者活动
創建於2013-01-05 01:04:48
推送於2018-12-18 00:30:11
最后一次提交2018-12-17 16:09:05
發布數7
最新版本名稱3.0.2 (發布於 2018-12-17 16:29:46)
第一版名稱1.0.0 (發布於 2014-12-10 00:14:14)
用户参与
星數77
關注者數5
派生數13
提交數129
已啟用問題?
問題數4
打開的問題數0
拉請求數2
打開的拉請求數0
關閉的拉請求數1
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?