@@ -21,13 +21,12 @@ it has its own excellent `documentation`_.
21
21
to use version 4.2 or higher to test the Symfony core code itself).
22
22
23
23
Each test - whether it's a unit test or a functional test - is a PHP class
24
- that should live in the ``Tests / `` subdirectory of your bundles . If you follow
24
+ that should live in the ``tests / `` directory of your application . If you follow
25
25
this rule, then you can run all of your application's tests with the following
26
26
command:
27
27
28
28
.. code-block :: bash
29
29
30
- # specify the configuration directory on the command line
31
30
$ phpunit
32
31
33
32
PHPunit is configured by the ``phpunit.xml.dist `` file in the root of your
@@ -63,11 +62,11 @@ called ``Calculator`` in the ``Util/`` directory of the app bundle::
63
62
}
64
63
}
65
64
66
- To test this, create a ``CalculatorTest `` file in the ``Tests /Util `` directory
65
+ To test this, create a ``CalculatorTest `` file in the ``tests/AppBundle /Util `` directory
67
66
of your bundle::
68
67
69
- // src /AppBundle/Tests /Util/CalculatorTest.php
70
- namespace AppBundle\ Tests\Util;
68
+ // tests /AppBundle/Util/CalculatorTest.php
69
+ namespace Tests\AppBundle \Util;
71
70
72
71
use AppBundle\Util\Calculator;
73
72
@@ -85,13 +84,13 @@ of your bundle::
85
84
86
85
.. note ::
87
86
88
- By convention, the ``Tests/ `` sub- directory should replicate the directory
89
- of your bundle for unit tests. So, if you're testing a class in your
90
- bundle's `` Util/ `` directory, put the test in the ``Tests /Util/ ``
87
+ By convention, the ``Tests/AppBundle `` directory should replicate the directory
88
+ of your bundle for unit tests. So, if you're testing a class in the
89
+ `` AppBundle/ Util/ `` directory, put the test in the ``tests/AppBundle /Util/ ``
91
90
directory.
92
91
93
92
Just like in your real application - autoloading is automatically enabled
94
- via the ``bootstrap .php.cache `` file (as configured by default in the
93
+ via the ``autoload .php `` file (as configured by default in the
95
94
``phpunit.xml.dist `` file).
96
95
97
96
Running tests for a given file or directory is also very easy:
@@ -102,13 +101,13 @@ Running tests for a given file or directory is also very easy:
102
101
$ phpunit
103
102
104
103
# run all tests in the Util directory
105
- $ phpunit src /AppBundle/Tests /Util
104
+ $ phpunit tests /AppBundle/Util
106
105
107
106
# run tests for the Calculator class
108
- $ phpunit src /AppBundle/Tests /Util/CalculatorTest.php
107
+ $ phpunit tests /AppBundle/Util/CalculatorTest.php
109
108
110
109
# run all tests for the entire Bundle
111
- $ phpunit src /AppBundle/
110
+ $ phpunit tests /AppBundle/
112
111
113
112
.. index ::
114
113
single: Tests; Functional tests
@@ -129,15 +128,15 @@ tests as far as PHPUnit is concerned, but they have a very specific workflow:
129
128
Your First Functional Test
130
129
~~~~~~~~~~~~~~~~~~~~~~~~~~
131
130
132
- Functional tests are simple PHP files that typically live in the ``Tests /Controller ``
133
- directory of your bundle. If you want to test the pages handled by your
131
+ Functional tests are simple PHP files that typically live in the ``tests/AppBundle /Controller ``
132
+ directory for your bundle. If you want to test the pages handled by your
134
133
``PostController `` class, start by creating a new ``PostControllerTest.php ``
135
134
file that extends a special ``WebTestCase `` class.
136
135
137
136
As an example, a test could look like this::
138
137
139
- // src /AppBundle/Tests /Controller/PostControllerTest.php
140
- namespace AppBundle\ Tests\Controller;
138
+ // tests /AppBundle/Controller/PostControllerTest.php
139
+ namespace Tests\AppBundle \Controller;
141
140
142
141
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
143
142
@@ -810,10 +809,8 @@ only.
810
809
Store the ``phpunit.xml.dist `` file in your code repository and ignore
811
810
the ``phpunit.xml `` file.
812
811
813
- By default, only the tests from your own custom bundles stored in the standard
814
- directories ``src/*/*Bundle/Tests ``, ``src/*/Bundle/*Bundle/Tests ``,
815
- ``src/*Bundle/Tests `` are run by the ``phpunit `` command, as configured
816
- in the ``phpunit.xml.dist `` file:
812
+ By default, only the tests stored in ``/tests `` are run via the ``phpunit `` command,
813
+ as configured in the ``phpunit.xml.dist `` file:
817
814
818
815
.. code-block :: xml
819
816
@@ -822,9 +819,7 @@ in the ``phpunit.xml.dist`` file:
822
819
<!-- ... -->
823
820
<testsuites >
824
821
<testsuite name =" Project Test Suite" >
825
- <directory >../src/*/*Bundle/Tests</directory >
826
- <directory >../src/*/Bundle/*Bundle/Tests</directory >
827
- <directory >../src/*Bundle/Tests</directory >
822
+ <directory >tests</directory >
828
823
</testsuite >
829
824
</testsuites >
830
825
<!-- ... -->
0 commit comments