twentytwo-labs / behat-open-api
Behat contexts
Installs: 5 394
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/twentytwo-labs/behat-open-api
Requires
- php: >=8.1
 - ext-json: *
 - ext-mbstring: *
 - behat/behat: ^3.0
 - friends-of-behat/mink-extension: ^2.6
 - guzzlehttp/psr7: ^2.3
 - symfony/http-foundation: ^5.0|^6.0|^7.0
 - symfony/property-access: ^5.0|^6.0|^7.0
 - symfony/serializer: ^5.0|^6.0|^7.0
 - twentytwo-labs/api-validator: ^2.0
 - twentytwo-labs/array-comparator: ^1.0
 - webmozart/assert: ^1.11
 
Requires (Dev)
- friends-of-behat/mink-browserkit-driver: ^1.6
 - friendsofphp/php-cs-fixer: ^3.8
 - infection/infection: ^0.28
 - phpstan/phpstan: ^1.11
 - phpunit/phpunit: ^10.4
 - squizlabs/php_codesniffer: ^3.6
 
README
Behat Open Api contexts provide most common Api Behat tests.
Installation
This extension requires:
- Behat 3+
 - Mink extension
 
Project dependency
- Install Composer
 - Require the package with Composer:
 
$ composer require --dev twentytwo-labs/behat-open-api
- Activate extension by specifying its class in your 
behat.yml: 
# behat.yml default: # ... extensions: TwentytwoLabs\BehatOpenApiExtension: schemaFile: "file:///path/to/your/schema" #optinal
Usage
In behat.yml, enable desired contexts:
default: suites: default: contexts: - TwentytwoLabs\BehatOpenApiExtension\Context\DebugContext: ~ - TwentytwoLabs\BehatOpenApiExtension\Context\RestContext: ~ - TwentytwoLabs\BehatOpenApiExtension\Context\JsonContext: ~ - TwentytwoLabs\BehatOpenApiExtension\Context\OpenApiContext: ~
Examples
- 
TwentytwoLabs\BehatOpenApiExtension\Context\DebugContext@Then print last response headers@Then print profiler link
 - 
TwentytwoLabs\BehatOpenApiExtension\Context\JsonContext@Then the response should be in JSON@Then the response should not be in JSON@Then the JSON node :node should be equal to :text@Then the JSON nodes should be equal to:@Then the JSON node :node should match :pattern@Then the JSON node :node should be null@Then the JSON node :node should not be null@Then the JSON node :node should be true@Then the JSON node :node should be false@Then the JSON node :node should be equal to the string :text@Then the JSON node :node should be equal to the number :number@Then the JSON node :node should have :count element(s)@Then the JSON node :node should contain :text@Then the JSON node :node should not contain :text- 
@Then the JSON nodes should contain: | ... | - 
@Then the JSON nodes should not contain: | ... | @Then the JSON node :name should exist@Then the JSON node :name should not exist@Then the JSON should be equal to:- 
@Then I should see JSON with key : | ... | - 
This step link to [Array-comparator](https://github.com/TwentytwoLabs/array-comparator package)@Then the JSON should be match to: | ... | 
 - 
TwentytwoLabs\BehatOpenApiExtension\Context\OpenApiContext@Then the response should be valid according to the operation id :operationId
 - 
TwentytwoLabs\BehatOpenApiExtension\Context\RestContext@Then I add :name header equal to :value@Given I send a :method request to :path- 
@Given I send a :method request to :path with parameters: | key | value | | ... | ..... | - 
@Given I send a :method request to :path with body: """ { #... } """ @Then /^the response status code should be equal to (?P<code>\d+)$/- 
@Then the response should be equal to: """ { # ... } """ @Then the response should be empty@Then the header :name should be equal to :value@Then the header :name should not be equal to :value@Then the header :name should contain :value@Then the header :name should not contain :value@Then the header :name should not exist@Then the header :name should match :regex@Then the header :name should not match :regex@Then the response should expire in the future@Then the response should be encoded in :encoding