You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is recommended to have unit and functional testing set up per each bundle and acceptance tests for set globally. Unit and Functional tests will check that each bundle work as expected while acceptance tests will check the UI and work of a system as a whole.
32
+
From Symfony 4 onwards there will be a top-level `tests` directory instead of a separate `Tests` directory in each bundle.
33
+
So to save you from reconfiguration in the future, it is recommended place unit, functional, and acceptance test files
Continue to <a href="http://codeception.com/docs/07-BDD">Behavior Driven Development Guide »</a>
111
113
</div>
112
114
113
-
## Bundle Setup
115
+
## Functional Testing
114
116
115
-
Each bundle should have its own Codeception setup. To have test configuration for `AppBundle` you should run:
117
+
There is no need to use `WebTestCase` to write functional tests. Symfony functional tests are written in the same manner as acceptance tests but are executed inside a framework. Codeception has the [Symfony Module](http://codeception.com/docs/modules/Symfony) for it. To create a functional test suite, run:
This will create `tests` dir inside `src/AppBundle`.
122
-
123
-
### Functional Testing
124
-
125
-
There is no need to use `WebTestCase` to write functional tests. Symfony functional tests are written in the same manner as acceptance tests but are executed inside a framework. Codeception has `Symfony` module for it. It is a good idea to separate functional and unit tests so it is recommended to create a new test suite for AppBundle
Functional tests are written in the same manner as acceptance tests. They also use scenario and `$I` actor object. The only difference is how they are executed. To run tests as Symfony test you should enable corresponding module in functional suite configureation file `src/Appundle/tests/functional.suite.yml`. Probably you want Doctrine to be included as well. Then you should use this configuration:
123
+
Functional tests are written in the same manner as acceptance tests. They also use scenario and `$I` actor object. The only difference is how they are executed. To run tests as Symfony test you should enable corresponding module in functional suite configuration file `tests/functional.suite.yml`. Probably you want Doctrine to be included as well. Then you should use this configuration:
132
124
133
125
```yaml
134
126
class_name: FunctionalTester
135
127
modules:
136
128
enabled:
137
129
- Symfony:
138
-
app_path: '../../app'
139
-
var_path: '../../app'
130
+
app_path: 'app'
131
+
var_path: 'app'
140
132
- Doctrine2:
141
133
depends: Symfony
142
-
- \AppBundle\Helper\Functional
134
+
- \Helper\Functional
143
135
```
144
136
145
137
<divclass="alert alert-warning">
@@ -154,13 +146,13 @@ modules:
154
146
155
147
### API Tests
156
148
157
-
API Tests are done at functional testing level but instead of testing HTML responses on user actions, they test requests and responses via protocols like REST or SOAP. To create api tests for `ApiBundle` bundle you should create a suite for them
149
+
API Tests are done at functional testing level but instead of testing HTML responses on user actions, they test requests and responses via protocols like REST or SOAP. To create api tests, you should create a suite for them:
158
150
159
151
```
160
-
php bin/codecept g:suite api -c src/ApiBundle
152
+
php bin/codecept g:suite api
161
153
```
162
154
163
-
You will need to enable `REST`, `Symfony` and `Doctrine` module in `src/ApiBundle/tests/api.suite.yml`:
155
+
You will need to enable `REST`, `Symfony` and `Doctrine` module in `tests/api.suite.yml`:
164
156
165
157
```yaml
166
158
class_name: ApiTester
@@ -171,11 +163,11 @@ modules:
171
163
depends: Symfony
172
164
- Doctrine2:
173
165
depends: Symfony
174
-
- \ApiBundle\Helper\Api
166
+
- \Helper\Api
175
167
config:
176
168
- Symfony:
177
-
app_path: '../../app'
178
-
var_path: '../../app'
169
+
app_path: 'app'
170
+
var_path: 'app'
179
171
180
172
```
181
173
@@ -190,22 +182,22 @@ Symfony module actions like `amOnPage` or `see` should not be available for test
190
182
191
183
### Unit Testing
192
184
193
-
You should put your unit tests for AppBundle into `src/AppBundle/tests/unit`. It is done to not mix them with functional and API tests. To start unit test suite for `AppBundle` shoule be created:
185
+
Create a unit test suite with:
194
186
195
187
```
196
-
php bin/codecept g:suite unit -c src/AppBundle
188
+
php bin/codecept g:suite unit
197
189
```
198
190
199
-
Codeception is powered by PHPUnit so unit and integration test work in a similar manner. To genereate a plain PHPUnit test for `Foo` class inside `AppBundle` please run
191
+
Codeception is powered by PHPUnit so unit and integration test work in a similar manner. To genereate a plain PHPUnit test for `Foo` class, run:
200
192
201
193
```
202
-
php bin/codecept g:phpunit unit Foo -c src/AppBundle
194
+
php bin/codecept g:phpunit unit Foo
203
195
```
204
196
205
197
This generates a standard test inherited from `PHPUnit_Framework_TestCase`. For integration tests you may use Codeception-enhanced format which allows accessing services DI container, Doctrine, and others. You will need to enable Doctrine2 and Symfony module in `unit.suite.yml` config. Such integration test is extending `Codeception\Test\Unit` class and created by running:
206
198
207
199
```
208
-
php bin/codecept g:test unit Foo -c src/AppBundle
200
+
php bin/codecept g:test unit Foo
209
201
```
210
202
211
203
Actions of Symfony and Doctrine2 modules will be accessible from `$this->tester` inside a test of `Codeception\Test\Unit`.
@@ -214,15 +206,3 @@ Actions of Symfony and Doctrine2 modules will be accessible from `$this->tester`
Continue to <ahref="http://codeception.com/docs/05-UnitTests">Unit Testing Guide »</a>.
216
208
</div>
217
-
218
-
219
-
### Running it all together
220
-
221
-
Codeception allows to execute all tests with different configurations in one runner. To execute all tests at once with `codecept run` you should include bundle configurations into global configuration file `codeception.yml` in the root of a project:
222
-
223
-
```yaml
224
-
include:
225
-
- src/*Bundle
226
-
```
227
-
228
-
Then running codeception tests from root directory will execute tests from all bundles as well as acceptance tests.
0 commit comments