macpaw / behat-api-context
Behat Context for testing Symfony Api
Installs: 121 858
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 4
Forks: 2
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^7.4 || ^8.0
- ext-json: *
- behat/behat: ^3.0
- macpaw/similar-arrays: ^1.0
- symfony/config: ^4.4 || ^5.4 || ^6.0 || ^7.0
- symfony/dependency-injection: ^4.4 || ^5.4.34 || ^6.0 || ^7.0.2
- symfony/http-client: ^4.4 || ^5.4 || ^6.0 || ^7.0
- symfony/http-kernel: ^4.4 || ^5.4 || ^6.0 || ^7.0
- symfony/routing: ^4.4 || ^5.4 || ^6.0 || ^7.0
Requires (Dev)
- phpstan/phpstan: ^1.4
- phpunit/phpunit: ^9.3
- slevomat/coding-standard: ^7.0
- squizlabs/php_codesniffer: ^3.6
Suggests
- doctrine/orm: ^2.0
- dev-develop
- v1.3.1
- v1.3.0
- v1.2.4
- v1.2.3
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.1
- v1.0.0
- dev-master
- dev-feat/check-entity-with-null-property
- dev-feat/ORC-1020-Publish-template-packages-to-packagis
- dev-feat/ORC-816-add-orm-context
- dev-feat/api-context-members-visibility
- dev-fix/refactorApiContext
This package is auto-updated.
Last update: 2024-10-28 10:20:27 UTC
README
Installation
Step 1: Download the Bundle
Open a command console, enter your project directory and execute:
Applications that use Symfony Flex in progress
$ composer require --dev macpaw/behat-api-context
Applications that don't use Symfony Flex
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ composer require --dev macpaw/behat-api-context
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Then, enable the bundle by adding it to the list of registered bundles
in the app/AppKernel.php
file of your project:
<?php // app/AppKernel.php // ... class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... BehatApiContext\BehatApiContextBundle::class => ['test' => true], ); // ... } // ... }
Step 2: Configure Behat
Go to behat.yml
# ... contexts: - BehatApiContext\Context\ApiContext # ...
If you want use orm context add to behat.yml
# ... contexts: - BehatApiContext\Context\ORMContext # ...
Usage
Runnable request parameters
Main use case when tests need to use current date.
Instead of static data in some testCaseName.feature
, like this:
""" { "dateTo": 1680360081, "dateFrom": 1680532881, } """
Can use, for example:
""" { "dateTo": "<(new DateTimeImmutable())->add(new DateInterval('P6D'))->getTimeStamp()>", "dateFrom": "<(new DateTimeImmutable())->add(new DateInterval('P2D'))->getTimeStamp()>", } """
To accomplish this, several conditions must be met:
- Runnable code must be a string and placed in
<>
- Should not add
return
keyword at the beginning, otherwise will get RuntimeException - Should not add
;
keyword at the end, otherwise will get RuntimeException - Should not use the code that returns
null
, otherwise will get RuntimeException