zxventures / api-extension
Behat extension for API Platform
Requires
- php: >=7.0
- api-platform/core: ^2.2
- behat/behat: ^3.4.3
- behat/mink-extension: ^2.3
- behat/symfony2-extension: ^2.1.4
- behatch/contexts: ^3.0
- doctrine/common: ^2.7
- doctrine/doctrine-cache-bundle: ^1.3.1
- doctrine/orm: ^2.5
- fzaninotto/faker: ^1.7
- psr/container: ^1.0
- symfony/config: ^3.4 || ^4.0
- symfony/dependency-injection: ^3.4 || ^4.0
- symfony/doctrine-bridge: ^2.8 || ^3.0 || ^4.0
- symfony/http-kernel: ^3.4 || ^4.0
- symfony/property-info: ^3.4 || ^4.0
- symfony/validator: ^3.4 || ^4.0
Requires (Dev)
- behat/mink-browserkit-driver: ^1.3
- doctrine/data-fixtures: ^1.2
- doctrine/doctrine-bundle: ^1.8
- friendsofphp/php-cs-fixer: ^2.10
- phpstan/phpstan: ^0.9
- phpunit/phpunit: ^4.5 || ^5.0 || ^6.0 || ^7.0
- symfony/asset: ^3.4 || ^4.0
- symfony/dom-crawler: ^3.0
- symfony/framework-bundle: ^3.4 || ^4.0
- symfony/twig-bundle: ^3.4 || ^4.0
This package is auto-updated.
Last update: 2023-08-16 19:58:26 UTC
README
This Behat extension requires following extensions, check their documentations for installation & usage:
This extension is just a shortcut to write some steps, it doesn't replace your custom steps. For instance, if you
want to test that updating a user updates its password, you still need to add a customer step like
And the user password has been successfully updated
.
Install
composer require --dev vincentchalamon/api-extension
Declare required extensions in your Behat configuration:
# behat.yml.dist default: # ... suites: default: contexts: - Behat\MinkExtension\Context\MinkContext - Behatch\Context\RestContext - Behatch\Context\JsonContext - ApiExtension\Context\ApiContext - ApiExtension\Context\FixturesContext extensions: Behat\Symfony2Extension: kernel: bootstrap: features/bootstrap/bootstrap.php class: App\Kernel Behat\MinkExtension: base_url: 'http://www.example.com/' sessions: default: symfony2: ~ Behatch\Extension: ~ # ... ApiExtension: ~
Using custom guessers for populator
# behat.yml.dist default: # ... extensions: # ... ApiExtension: guessers: - App\Populator\Guesser\AcustomGuesser - App\Populator\Guesser\AnotherCustomGuesser
Usage with Symfony FrameworkBundle < 4.1
Running with Symfony FrameworkBundle < 4.1, you need to override some private services:
# config/services_test.yaml # Hack for Behat: allow to inject some private services services: test.property_info: parent: property_info public: true test.api_platform.metadata.resource.metadata_factory.annotation: parent: api_platform.metadata.resource.metadata_factory.annotation public: true test.api_platform.iri_converter: parent: api_platform.iri_converter public: true test.annotation_reader: parent: annotation_reader public: true test.router: parent: router public: true
# behat.yml.dist default: # ... extensions: # ... ApiExtension: services: metadataFactory: '@test.api_platform.metadata.resource.metadata_factory.annotation' iriConverter: '@test.api_platform.iri_converter' registry: '@doctrine' propertyInfo: '@test.property_info' annotationReader: '@test.annotation_reader' router: '@test.router'
Usage
FixturesContext provides the following steps:
the following <name>
there is <nb> <name>
there is a <name>
there is an <name>
there are <nb> <name>
there are <name>
there are <nb> <name> with:
ApiContext provides the following steps:
I get a list of <name>
I get a list of <name> filtered by <filter>
I get a list of <name> ordered by <filter>
I create a <name>
I create an <name>
I create a <name> using group <serialization-group>
I create a <name> using groups <serialization-groups>
I create an <name> using group <serialization-group>
I create an <name> using groups <serialization-groups>
I create a <name> with:
I create an <name> with:
I create a <name> using group <serialization-group> with:
I create a <name> using groups <serialization-groups> with:
I create an <name> using group <serialization-group> with:
I create an <name> using groups <serialization-groups> with:
I get a <name>
I get an <name>
I get the <name> <value>
I delete a <name>
I delete an <name>
I delete the <name> <value>
I update a <name>
I update an <name>
I update the <name> <value>
I update a <name> with:
I update an <name> with:
I update the <name> <value> with:
the request is invalid
the <name> is not found
the method is not allowed
I see a <name>
I see an <name>
I see a list of <name>
I see a list of <nb> <name>
I don't see any <name>
print <name> list JSON schema
print <name> item JSON schema
print last JSON request
Example:
Feature: Using API-Platform, I can get, create, update & delete beers. Scenario: I can get a list of beers Given there are beers When I get a list of beers Then I see a list of beers Scenario: I can get a list of beers filtered by name Given there are beers When I get a list of beers filtered by name=Chouffe Then I don't see any beer Scenario: I can create a beer When I create a beer Then I see a beer Scenario: I can create a beer When I create a beer with: | name | | Chouffe | Then I see a beer Scenario: I can update a beer Given there is a beer When I update a beer Then I see a beer Scenario: I can update a beer and fill its new name Given there is a beer When I update a beer with: | name | | Chouffe | Then I see a beer Scenario: I can update a beer by its name Given the following beer: | name | | Chouffe | When I update the beer Chouffe Then I see a beer Scenario: I can update a beer by its name and fill its new name Given the following beer: | name | | Chouffe | When I update the beer Chouffe with: | name | | Kwak | Then I see a beer Scenario: I can get a beer Given there is a beer When I get a beer Then I see a beer Scenario: I can get a beer by its name Given the following beer: | name | | Chouffe | When I get the beer Chouffe Then I see a beer Scenario: I cannot get a non-existing beer When I get a beer Then the beer is not found Scenario: I can delete a beer Given there is a beer When I delete a beer Then the beer has been successfully deleted Scenario: I can delete a beer by its name Given the following beer: | name | | Chouffe | When I delete the beer Chouffe Then the beer has been successfully deleted
Add faker provider
To use a custom faker provider from fzaninotto/Faker, update your Behat configuration as following:
# behat.yml.dist default: # ... extensions: # ... ApiExtension: # ... providers: - App\Faker\Provider\MiscellaneousProvider