Skip to content

Commit 0fe348a

Browse files
authored
Merge pull request Codeception#139 from ThomasLandauer/patch-2
Recommending /tests directory instead of bundle-specific Tests-direct…
2 parents a85c868 + dbb3eb4 commit 0fe348a

File tree

1 file changed

+21
-41
lines changed

1 file changed

+21
-41
lines changed

for/symfony.md

Lines changed: 21 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ composer require codeception/codeception --dev
3838

3939
## Setup
4040

41-
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.
41+
From Symfony 4 onwards there will be a top-level `tests` directory instead of a separate `Tests` directory in each bundle.
42+
So to save you from reconfiguration in the future, it is recommended place unit, functional, and acceptance test files
43+
into `/tests`.
4244

4345
### Project Setup
4446

@@ -119,36 +121,26 @@ php bin/codecept gherkin:snippets
119121
Continue to <a href="http://codeception.com/docs/07-BDD">Behavior Driven Development Guide &raquo;</a>
120122
</div>
121123
122-
## Bundle Setup
124+
## Functional Testing
123125
124-
Each bundle should have its own Codeception setup. To have test configuration for `AppBundle` you should run:
126+
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:
125127
126128
```
127-
php bin/codecept bootstrap --empty src/AppBundle --namespace AppBundle
129+
php bin/codecept g:suite functional
128130
```
129131
130-
This will create `tests` dir inside `src/AppBundle`.
131-
132-
### Functional Testing
133-
134-
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
135-
136-
```
137-
php bin/codecept g:suite functional -c src/AppBundle
138-
```
139-
140-
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:
132+
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:
141133
142134
```yaml
143135
class_name: FunctionalTester
144136
modules:
145137
enabled:
146138
- Symfony:
147-
app_path: '../../app'
148-
var_path: '../../app'
139+
app_path: 'app'
140+
var_path: 'app'
149141
- Doctrine2:
150142
depends: Symfony
151-
- \AppBundle\Helper\Functional
143+
- \Helper\Functional
152144
```
153145

154146
<div class="alert alert-warning">
@@ -163,13 +155,13 @@ modules:
163155

164156
### API Tests
165157

166-
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
158+
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:
167159

168160
```
169-
php bin/codecept g:suite api -c src/ApiBundle
161+
php bin/codecept g:suite api
170162
```
171163

172-
You will need to enable `REST`, `Symfony` and `Doctrine` module in `src/ApiBundle/tests/api.suite.yml`:
164+
You will need to enable `REST`, `Symfony` and `Doctrine` module in `tests/api.suite.yml`:
173165

174166
```yaml
175167
class_name: ApiTester
@@ -180,11 +172,11 @@ modules:
180172
depends: Symfony
181173
- Doctrine2:
182174
depends: Symfony
183-
- \ApiBundle\Helper\Api
175+
- \Helper\Api
184176
config:
185177
- Symfony:
186-
app_path: '../../app'
187-
var_path: '../../app'
178+
app_path: 'app'
179+
var_path: 'app'
188180

189181
```
190182

@@ -199,22 +191,22 @@ Symfony module actions like `amOnPage` or `see` should not be available for test
199191

200192
### Unit Testing
201193

202-
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:
194+
Create a unit test suite with:
203195

204196
```
205-
php bin/codecept g:suite unit -c src/AppBundle
197+
php bin/codecept g:suite unit
206198
```
207199

208-
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
200+
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:
209201

210202
```
211-
php bin/codecept g:phpunit unit Foo -c src/AppBundle
203+
php bin/codecept g:phpunit unit Foo
212204
```
213205

214206
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:
215207

216208
```
217-
php bin/codecept g:test unit Foo -c src/AppBundle
209+
php bin/codecept g:test unit Foo
218210
```
219211

220212
Actions of Symfony and Doctrine2 modules will be accessible from `$this->tester` inside a test of `Codeception\Test\Unit`.
@@ -223,15 +215,3 @@ Actions of Symfony and Doctrine2 modules will be accessible from `$this->tester`
223215
<span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
224216
Continue to <a href="http://codeception.com/docs/05-UnitTests">Unit Testing Guide &raquo;</a>.
225217
</div>
226-
227-
228-
### Running it all together
229-
230-
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:
231-
232-
```yaml
233-
include:
234-
- src/*Bundle
235-
```
236-
237-
Then running codeception tests from root directory will execute tests from all bundles as well as acceptance tests.

0 commit comments

Comments
 (0)