23/07
2018
Helper context classes for easy ATDD in a Api Rest with Behat, (*1)
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
Examples:, (*2)
#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
```gherkin, (*3)
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" } """, (*4)
Don`t forget your given clauses for prepare your scenarios!!! # Good practices Is a good practice create another context that reset your environment and execute before any test ```php /** @BeforeScenario */ public function clearEnvironment() { //... clear your envirnomnet }