1
- Behat Api Context Bundle
2
- =================================
1
+ # Behat Api Context Bundle
3
2
4
3
| Version | Build Status | Code Coverage |
5
4
| :---------:| :-------------:| :-----:|
6
- | ` master ` | [ ![ CI] [ master Build Status Image ]] [ master Build Status ] | [ ![ Coverage Status] [ master Code Coverage Image ]] [ master Code Coverage ] |
7
- | ` develop ` | [ ![ CI] [ develop Build Status Image ]] [ develop Build Status ] | [ ![ Coverage Status] [ develop Code Coverage Image ]] [ develop Code Coverage ] |
5
+ | ` master ` | [ ![ CI] [ master Build Status Image ]] [ master Build Status ] | [ ![ Coverage Status] [ master Code Coverage Image ]] [ master Code Coverage ] |
6
+ | ` develop ` | [ ![ CI] [ develop Build Status Image ]] [ develop Build Status ] | [ ![ Coverage Status] [ develop Code Coverage Image ]] [ develop Code Coverage ] |
8
7
9
- Installation
10
- ============
8
+ ## Installation
9
+
10
+ ### Step 1: Download the Bundle
11
11
12
- Step 1: Download the Bundle
13
- ----------------------------------
14
12
Open a command console, enter your project directory and execute:
15
13
16
- ### Applications that use Symfony Flex [ in progress] ( https://github.com/MacPaw/BehatRedisContext/issues/2 )
14
+ #### Applications that use Symfony Flex [ in progress] ( https://github.com/MacPaw/BehatRedisContext/issues/2 )
17
15
18
- ``` console
19
- $ composer require --dev macpaw/behat-api-context
16
+ ``` bash
17
+ composer require --dev macpaw/behat-api-context
20
18
```
21
19
22
- ### Applications that don't use Symfony Flex
20
+ #### Applications that don't use Symfony Flex
23
21
24
- Open a command console, enter your project directory and execute the
25
- following command to download the latest stable version of this bundle:
22
+ Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
26
23
27
- ``` console
28
- $ composer require --dev macpaw/behat-api-context
24
+ ``` bash
25
+ composer require --dev macpaw/behat-api-context
29
26
```
30
27
31
28
This command requires you to have Composer installed globally, as explained
@@ -57,9 +54,11 @@ class AppKernel extends Kernel
57
54
}
58
55
```
59
56
60
- Step 2: Configure Behat
61
- =============
62
- Go to ` behat.yml `
57
+ ---
58
+
59
+ ## Step 2: Configure Behat
60
+
61
+ Go to ` behat.yml ` :
63
62
64
63
``` yaml
65
64
# ...
@@ -68,45 +67,92 @@ Go to `behat.yml`
68
67
# ...
69
68
```
70
69
71
- If you want use orm context add to ` behat.yml `
70
+ ### Optional: Enable ORMContext
71
+
72
+ If you want to use ` ORMContext ` , you need to have ` doctrine/orm ` installed:
73
+
74
+ ``` bash
75
+ composer require --dev doctrine/orm
76
+ ```
77
+
78
+ Then, update your ` behat.yml ` :
79
+
72
80
``` yaml
73
81
# ...
74
82
contexts :
75
83
- BehatApiContext\Context\ORMContext
76
84
# ...
77
85
```
78
86
79
- Usage
80
- =============
87
+ ---
88
+
89
+ ## Configuration
90
+
91
+ By default, the bundle has the following configuration:
92
+
93
+ ``` yaml
94
+ behat_api_context :
95
+ kernel_reset_managers : []
96
+ use_orm_context : true
97
+ ` ` `
98
+
99
+ | ORM Installed | Default ` use_orm_context` |
100
+ |:-------------:|:-------------------------:|
101
+ | Yes | `true` |
102
+ | No | `false` |
103
+
104
+ You can override it manually in your `config/packages/test/behat_api_context.yaml` :
81
105
82
- Runnable request parameters
83
- ----------------------------------
84
- Main use case when tests need to use current date.
85
- Instead of static data in some ` testCaseName.feature ` , like this:
86
- ``` feature
106
+ ` ` ` yaml
107
+ behat_api_context:
108
+ use_orm_context: false
109
+ ` ` `
110
+
111
+ or
112
+
113
+ ` ` ` yaml
114
+ behat_api_context:
115
+ use_orm_context: true
116
+ ` ` `
117
+
118
+ depending on your needs.
119
+
120
+ ---
121
+
122
+ # Usage
123
+
124
+ # ## Runnable request parameters
125
+
126
+ Main use case when tests need to use the current date.
127
+ Instead of static data in some `.feature` file like this :
128
+
129
+ ` ` ` gherkin
87
130
"""
88
131
{
89
132
"dateTo": 1680360081,
90
- "dateFrom": 1680532881,
133
+ "dateFrom": 1680532881
91
134
}
92
135
"""
93
136
` ` `
94
- Can use, for example:
95
- ``` feature
137
+
138
+ You can use dynamic expressions :
139
+
140
+ ` ` ` gherkin
96
141
"""
97
142
{
98
143
"dateTo": "<(new DateTimeImmutable())->add(new DateInterval('P6D'))->getTimeStamp()>",
99
- "dateFrom": "<(new DateTimeImmutable())->add(new DateInterval('P2D'))->getTimeStamp()>",
144
+ "dateFrom": "<(new DateTimeImmutable())->add(new DateInterval('P2D'))->getTimeStamp()>"
100
145
}
101
146
"""
102
147
` ` `
103
148
104
- #### To accomplish this, several conditions must be met:
105
- - Runnable code must be a string and placed in ` <> `
106
- - Should not add ` return ` keyword at the beginning, otherwise will get RuntimeException
107
- - Should not add ` ; ` keyword at the end, otherwise will get RuntimeException
108
- - Should not use the code that returns ` null ` , otherwise will get RuntimeException
149
+ # ### To achieve this, several conditions must be met:
150
+ - Runnable code must be a string and placed inside `<>`.
151
+ - Do not add `return` keyword at the beginning, otherwise a `RuntimeException` will be thrown.
152
+ - Do not add `;` at the end of the expression , otherwise a `RuntimeException` will be thrown.
153
+ - Avoid code that returns `null`, otherwise a `RuntimeException` will be thrown.
109
154
155
+ ---
110
156
111
157
[master Build Status] : https://github.com/macpaw/behat-api-context/actions?query=workflow%3ACI+branch%3Amaster
112
158
[master Build Status Image] : https://github.com/macpaw/behat-api-context/workflows/CI/badge.svg?branch=master
0 commit comments