2017 © Pedro Peláez
 

library bdd-api-io-context

image

pccomponentes/bdd-api-io-context

  • Monday, July 23, 2018
  • by Aaronidas
  • Repository
  • 2 Watchers
  • 0 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 100 % Grown

The README.md

Bdd API IO Context

Helper context classes for easy ATDD in a Api Rest with Behat, (*1)

Enable MinkExtension in your behat.yml

default:
  extensions:
    Behat\MinkExtension:
      sessions:
        my_session:
          symfony2: ~

Add Request and Response contexts to your paths

  suites:
    yoursuitte:
      paths: [ tests/api/features/product ]
      contexts:
        - Pccomponentes\BddApiIOContext\Infrastructure\Behat\ApiContext\ApiRequestContext
        - Pccomponentes\BddApiIOContext\Infrastructure\Behat\ApiContext\ApiResponseContext

Now, you can use the contexts in your features

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)

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" } """, (*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 }

The Versions