pccomponentes/bdd-api-io-context

This package is abandoned and no longer maintained. The author suggests using the pccomponentes/open-api-messaging-context package instead.
There is no license information available for the latest version (v0.0.4) of this package.

v0.0.4 2018-09-27 09:58 UTC

This package is auto-updated.

Last update: 2020-06-15 10:41:40 UTC


README

Helper context classes for easy ATDD in a Api Rest with Behat

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:

#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"
    }
    """

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

    /** @BeforeScenario */
    public function clearEnvironment()
    {
        //... clear your envirnomnet
    }