|
1 | 1 | # Behat Api Context Bundle |
2 | 2 |
|
3 | | -| Version | Build Status | Code Coverage | Latest Release | |
4 | | -|:---------:|:---------------------------------------------------------:|:------------------------------------------------------------------------:|:-----------------:| |
5 | | -| `master` | [![CI][master Build Status Image]][master Build Status] | [![Coverage Status][master Code Coverage Image]][master Code Coverage] | ![Latest Release] | |
| 3 | +| Version | Build Status | Code Coverage | Latest Release | |
| 4 | +| :-------: | :-------------------------------------------------------: | :----------------------------------------------------------------------: | :---------------: | |
| 5 | +| `master` | [![CI][master Build Status Image]][master Build Status] | [![Coverage Status][master Code Coverage Image]][master Code Coverage] | ![Latest Release] | |
6 | 6 | | `develop` | [![CI][develop Build Status Image]][develop Build Status] | [![Coverage Status][develop Code Coverage Image]][develop Code Coverage] | - | |
7 | 7 |
|
8 | | -## ⚠️ Deprecation Notice |
9 | | - |
10 | | -> The `ORMContext` has been **deprecated** and **removed** from this package. |
11 | | -> Please use the standalone package [`macpaw/behat-orm-context`](https://github.com/macpaw/behat-orm-context) instead. |
12 | | -
|
13 | | ---- |
14 | | - |
15 | | -## Installation |
16 | | - |
17 | | -### Step 1: Install the Bundle |
18 | | - |
19 | | -Run the following command in your project directory to install the bundle as a development dependency: |
20 | | - |
21 | | -```bash |
22 | | - composer require --dev macpaw/behat-api-context |
23 | | -``` |
24 | | - |
25 | | -> If you are using Symfony Flex, the bundle will be registered automatically. |
26 | | -> Otherwise, follow Step 2 to register the bundle manually. |
27 | | -### Step 2: Register the Bundle |
28 | | - |
29 | | -If your project does **not** use Symfony Flex or the bundle does not provide a recipe, manually register it in `config/bundles.php`: |
30 | | - |
31 | | -```php |
32 | | -<?php |
33 | | -// config/bundles.php |
34 | | - |
35 | | -return [ |
36 | | - // ... |
37 | | - BehatApiContext\BehatApiContextBundle::class => ['test' => true], |
38 | | -]; |
39 | | -``` |
40 | | - |
41 | | -> ℹ️ The bundle should only be enabled in the `test` environment. |
42 | | -
|
43 | | -### Step 3: Configure Behat |
44 | | - |
45 | | -Update your `behat.yml`: |
46 | | - |
47 | | -```yaml |
48 | | -default: |
49 | | - suites: |
50 | | - default: |
51 | | - contexts: |
52 | | - - BehatApiContext\Context\ApiContext |
53 | | - - BehatApiContext\Context\ORMContext |
54 | | -``` |
55 | | -
|
56 | | -> If you also want to use `ORMContext`, install [macpaw/behat-orm-context](https://github.com/macpaw/behat-orm-context) and follow its setup instructions. |
57 | | - |
58 | | -> 📄 **Migration Notice:** `OrmContext` will be removed from `behat-api-context` in the next major release. |
59 | | -> Please migrate to [`behat-orm-context`](https://github.com/macpaw/behat-orm-context) to avoid test failures. |
60 | | -> See the full [ORMContext Migration Plan](./docs/ormcontext-migration.md) for step-by-step instructions. |
61 | | - |
62 | | - |
63 | 8 | --- |
64 | 9 |
|
65 | | -## Configuration |
66 | | - |
67 | | -By default, the bundle provides the following configuration: |
68 | | -> This bundle does not yet include a Symfony recipe to automatically create the configuration file. |
69 | | -> If you need a specific configuration, you have to add it manually. |
70 | | -> [Recipe in progress](https://github.com/MacPaw/BehatRedisContext/issues/2) |
71 | | - |
72 | | -```yaml |
73 | | -behat_api_context: |
74 | | - kernel_reset_managers: [] |
75 | | -``` |
76 | | - |
77 | | -You can also add your own reset manager by overriding the configuration manually in `config/packages/test/behat_api_context.yaml`: |
78 | | - |
79 | | -```yaml |
80 | | -behat_api_context: |
81 | | - kernel_reset_managers: |
82 | | - - BehatApiContext\Service\ResetManager\DoctrineResetManager |
83 | | -``` |
| 10 | +Behat API Context provides a set of Behat steps for testing RESTful APIs with support for dynamic request parameters, context persistence, and Symfony integration. |
84 | 11 |
|
85 | 12 | --- |
86 | 13 |
|
87 | | -## Usage |
88 | | - |
89 | | -### Runnable request parameters |
90 | | - |
91 | | -Main use case when tests need to use the current date. |
92 | | -Instead of static data in some `.feature` file like this: |
93 | | - |
94 | | -```gherkin |
95 | | -""" |
96 | | -{ |
97 | | - "dateTo": 1680360081, |
98 | | - "dateFrom": 1680532881 |
99 | | -} |
100 | | -""" |
101 | | -``` |
102 | | - |
103 | | -You can use dynamic expressions: |
104 | | - |
105 | | -```gherkin |
106 | | -""" |
107 | | -{ |
108 | | - "dateTo": "<(new DateTimeImmutable())->add(new DateInterval('P6D'))->getTimestamp()>", |
109 | | - "dateFrom": "<(new DateTimeImmutable())->add(new DateInterval('P2D'))->getTimestamp()>" |
110 | | -} |
111 | | -""" |
112 | | -``` |
| 14 | +## 📄 Documentation |
113 | 15 |
|
114 | | -#### To achieve this, several conditions must be met: |
115 | | -- Runnable code must be a string and placed inside `<>`. |
116 | | -- Do not add `return` keyword at the beginning, otherwise a `RuntimeException` will be thrown. |
117 | | -- Do not add a semicolon (`;`) at the end of the expression, otherwise a `RuntimeException` will be thrown. |
118 | | -- Avoid code that returns `null`, otherwise a `RuntimeException` will be thrown. |
| 16 | +- [Installation & Configuration](docs/install.md) |
| 17 | +- [Available Steps](docs/steps.md) |
| 18 | +- [Usage Examples](docs/examples.md) |
| 19 | +- [Runnable Parameters](docs/runnable-parameters.md) |
119 | 20 |
|
120 | 21 | --- |
121 | 22 |
|
|
0 commit comments