2017 © Pedro Peláez
 

library symfony-api-extension

Provides functionality for testing Symfony APIs with Behat.

image

persata/symfony-api-extension

Provides functionality for testing Symfony APIs with Behat.

  • Sunday, July 22, 2018
  • by persata
  • Repository
  • 3 Watchers
  • 1 Stars
  • 235 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 19 Versions
  • 34 % Grown

The README.md

Symfony API Extension License Version Build Status

Provides functionality for testing Symfony APIs with Behat., (*1)

This package offers an ApiClient class that can be shared between all relevant contexts that require being able to modify the request or inspect the response., (*2)

Requires the FriendsOfBehat SymfonyExtension., (*3)

Usage

  1. Install via Composer:, (*4)

    $ composer require persata/symfony-api-extension --dev
    
  2. Enable and configure in your Behat configuration:, (*5)

    # behat.yml
    default:
        suites:
            default:
                contexts:
                    - Persata\SymfonyApiExtension\Context\ApiContext: ~
    
        extensions:
            Persata\SymfonyApiExtension: ~
            FriendsOfBehat\SymfonyExtension:
                kernel:
                    bootstrap: vendor/autoload.php
    

Additional Custom Contexts

This package provides a ContextInitializer that will set the shared ApiClient on any Behat Contexts that implement the ApiClientAwareContext. It is best to extend the RawApiContext as this already includes the getter & setter for the ApiClient instance., (*6)

ContextServiceExtension Integration

If using the FriendsOfBehat ContextServiceExtension, declare the ApiContext service like so:, (*7)

services:
    # ...
    Persata\SymfonyApiExtension\Context\ApiContext:
        tags:
            - { name: fob.context_service }

If you need additional context services with access to the same shared ApiClient instance, have them extend RawApiContext and then declare the service like so:, (*8)

services:
    # ...
    TheClass\Of\Your\CustomContext:
        tags:
            - { name: fob.context_service }

FOSRest Form Validation

If you are using the FOSRestBundle within your Symfony application and are making use of the form response features, there is an additional FOSRestFormValidationContext class provided for testing for the presence or omission of errors:, (*9)

Then the JSON response should have the error "This value should not be null." at "user.firstName"
And the JSON response should not have any errors on "user.lastName"

Example Scenario

Scenario: Testing Basic JSON Endpoint
    Given the "Authorization" request header is "Bearer MyToken"
    When the request is sent using GET to "/example-endpoint"
    Then the response status code should be 200
    And the response content type should be JSON
    And the response content should be valid JSON
    And the JSON response should be
    """
    {
        "hello": "world"
    }
    """
    And the JSON response should have the structure
    """
    [
        "hello"
    ]
    """

Extension Configuration

# behat.yml
default:
    extensions:
        Persata\SymfonyApiExtension:
            base_url: 'http://my-api.local' # Base URL used for requests sent to the Symfony kernel. Defaults to null.
            files_path: "%paths.base%/src/Behat/Resources/fixtures/" # Base directory of files to be used for upload tests. Defaults to null.

The Versions

22/07 2018

dev-symfony-4-support

dev-symfony-4-support

Provides functionality for testing Symfony APIs with Behat.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ross Kinsman

06/03 2018

dev-master

9999999-dev

Provides functionality for testing Symfony APIs with Behat.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ross Kinsman

06/03 2018

0.2.7

0.2.7.0

Provides functionality for testing Symfony APIs with Behat.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ross Kinsman

01/02 2018

0.2.6

0.2.6.0

Provides functionality for testing Symfony APIs with Behat.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ross Kinsman

29/01 2018

0.2.5

0.2.5.0

Provides functionality for testing Symfony APIs with Behat.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ross Kinsman

29/01 2018

0.2.4

0.2.4.0

Provides functionality for testing Symfony APIs with Behat.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ross Kinsman

29/01 2018

0.2.3

0.2.3.0

Provides functionality for testing Symfony APIs with Behat.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ross Kinsman

26/01 2018

0.2.2

0.2.2.0

Provides functionality for testing Symfony APIs with Behat.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ross Kinsman

04/01 2018

0.2.1

0.2.1.0

Provides functionality for testing Symfony APIs with Behat.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ross Kinsman

18/12 2017

0.2.0

0.2.0.0

Provides functionality for testing Symfony APIs with Behat.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ross Kinsman

30/11 2017

0.1.6

0.1.6.0

Provides functionality for testing Symfony APIs with Behat.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ross Kinsman

28/11 2017

dev-feature/json-response-array-count-check

dev-feature/json-response-array-count-check

Provides functionality for testing Symfony APIs with Behat.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ross Kinsman

27/11 2017

dev-field-errors

dev-field-errors

Provides functionality for testing Symfony APIs with Behat.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ross Kinsman

23/10 2017

0.1.5

0.1.5.0

Provides functionality for testing Symfony APIs with Behat.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ross Kinsman

18/10 2017

0.1.4

0.1.4.0

Provides functionality for testing Symfony APIs with Behat.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ross Kinsman

13/10 2017

0.1.3

0.1.3.0

Provides functionality for testing Symfony APIs with Behat.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ross Kinsman

12/10 2017

0.1.2

0.1.2.0

Provides functionality for testing Symfony APIs with Behat.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ross Kinsman

04/10 2017

0.1.1

0.1.1.0

Provides functionality for testing Symfony APIs with Behat.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ross Kinsman

03/10 2017

0.1.0

0.1.0.0

Provides functionality for testing Symfony APIs with Behat.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ross Kinsman