pccomponentes / bdd-api-io-context
v0.0.4
2018-09-27 09:58 UTC
Requires
- behat/behat: dev-master
- behat/mink: dev-master
- behat/mink-browserkit-driver: ^1.3
- behat/mink-extension: ^2.3.1@dev
- behat/symfony2-extension: ^2.1
- phpunit/phpunit: ^7.0
- swaggest/json-schema: ^0.12.3
This package is auto-updated.
Last update: 2020-06-15 10:41:40 UTC
README
用于在Api Rest中通过Behat轻松实现ATDD的辅助上下文类
在您的 behat.yml 中启用 MinkExtension
default: extensions: Behat\MinkExtension: sessions: my_session: symfony2: ~
将请求和响应上下文添加到您的路径中
suites: yoursuitte: paths: [ tests/api/features/product ] contexts: - Pccomponentes\BddApiIOContext\Infrastructure\Behat\ApiContext\ApiRequestContext - Pccomponentes\BddApiIOContext\Infrastructure\Behat\ApiContext\ApiResponseContext
现在,您可以在功能中使用了这些上下文
示例
#POST Scenario: Create a product When I send a POST request to "/products" with body: """ { "product_id": "73118479-28a6-401e-9dad-6c88eac17484", "name": "fake product" } """ Then the response should be empty And the response status code should be 201
#GET Scenario: Find an existing product When I send a GET request to "/products/73118479-28a6-401e-9dad-6c88eac17484" Then the response status code should be 200 And the response content should be: """ { "id": "73118479-28a6-401e-9dad-6c88eac17484", "name": "fake product" } """
别忘了为准备场景提供的给定条款!!!
良好实践
创建另一个上下文以重置环境并在任何测试之前执行,这是一种良好实践。
/** @BeforeScenario */ public function clearEnvironment() { //... clear your envirnomnet }