Skip to content

Commit 5d4a3a4

Browse files
committed
bug #3343 [Testing] Fix phpunit test dir paths (bicpi)
This PR was merged into the 2.3 branch. Discussion ---------- [Testing] Fix phpunit test dir paths | Q | A | ------------- | --- | Doc fix? | yes | New docs? | no | Applies to | all | Fixed tickets | - Maybe there could be further improvements: The paragraph that follows is a bit confusing. It says *...the following configuration adds the tests from the installed third-party bundles* and then the tests from AcmeDemoBundle are included with `<directory>../src/Acme/Bundle/*Bundle/Tests</directory>`. Mh, the AcmeDemoBundle is a 3rd party bundle that resides in `src`? Shouldn't it include a directory from `vendors` instead to demonstrate this? In addition, the AcmeDemoBundle tests are covered by the standard configuration, so there should be no need for an extra configuration. It continues with *To include other directories in the code coverage..* and then some dirs from the AcmeDemoBundle are excluded which is also covered by the standard configuration. What do you think, should I make some more updates here? Commits ------- 75bd1e5 Fixes after review d17a20f Further tweaks to the PHPUnit configuration description 61cdfcc [Testing] Fix phpunit test dir paths
2 parents 6951460 + 75bd1e5 commit 5d4a3a4

File tree

1 file changed

+51
-28
lines changed

1 file changed

+51
-28
lines changed

Diff for: book/testing.rst

+51-28
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ it has its own excellent `documentation`_.
2121
needed to test the Symfony core code itself.
2222

2323
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/`` subdirectory of your bundles. If you follow
2525
this rule, then you can run all of your application's tests with the following
2626
command:
2727

@@ -771,47 +771,70 @@ PHPUnit Configuration
771771
~~~~~~~~~~~~~~~~~~~~~
772772

773773
Each application has its own PHPUnit configuration, stored in the
774-
``phpunit.xml.dist`` file. You can edit this file to change the defaults or
775-
create a ``phpunit.xml`` file to tweak the configuration for your local machine.
774+
``app/phpunit.xml.dist`` file. You can edit this file to change the defaults or
775+
create an ``app/phpunit.xml`` file to setup a configuration for your local
776+
machine only.
776777

777778
.. tip::
778779

779-
Store the ``phpunit.xml.dist`` file in your code repository, and ignore the
780+
Store the ``phpunit.xml.dist`` file in your code repository and ignore the
780781
``phpunit.xml`` file.
781782

782-
By default, only the tests stored in "standard" bundles are run by the
783-
``phpunit`` command (standard being tests in the ``src/*/Bundle/Tests`` or
784-
``src/*/Bundle/*Bundle/Tests`` directories) But you can easily add more
785-
directories. For instance, the following configuration adds the tests from
786-
the installed third-party bundles:
783+
By default, only the tests from your own custom bundles stored in the standard
784+
directories ``src/*/*Bundle/Tests`` or ``src/*/Bundle/*Bundle/Tests`` are run
785+
by the ``phpunit`` command, as configured in the ``phpunit.xml.dist`` file:
787786

788787
.. code-block:: xml
789788
790-
<!-- hello/phpunit.xml.dist -->
791-
<testsuites>
792-
<testsuite name="Project Test Suite">
793-
<directory>../src/*/*Bundle/Tests</directory>
794-
<directory>../src/Acme/Bundle/*Bundle/Tests</directory>
795-
</testsuite>
796-
</testsuites>
789+
<!-- app/phpunit.xml.dist -->
790+
<phpunit>
791+
<!-- ... -->
792+
<testsuites>
793+
<testsuite name="Project Test Suite">
794+
<directory>../src/*/*Bundle/Tests</directory>
795+
<directory>../src/*/Bundle/*Bundle/Tests</directory>
796+
</testsuite>
797+
</testsuites>
798+
<!-- ... -->
799+
</phpunit>
800+
801+
But you can easily add more directories. For instance, the following
802+
configuration adds tests from a custom ``lib/tests`` directory:
803+
804+
.. code-block:: xml
805+
806+
<!-- app/phpunit.xml.dist -->
807+
<phpunit>
808+
<!-- ... -->
809+
<testsuites>
810+
<testsuite name="Project Test Suite">
811+
<!-- ... --->
812+
<directory>../lib/tests</directory>
813+
</testsuite>
814+
</testsuites>
815+
<!-- ... --->
816+
</phpunit>
797817
798818
To include other directories in the code coverage, also edit the ``<filter>``
799819
section:
800820

801821
.. code-block:: xml
802822
803-
<!-- ... -->
804-
<filter>
805-
<whitelist>
806-
<directory>../src</directory>
807-
<exclude>
808-
<directory>../src/*/*Bundle/Resources</directory>
809-
<directory>../src/*/*Bundle/Tests</directory>
810-
<directory>../src/Acme/Bundle/*Bundle/Resources</directory>
811-
<directory>../src/Acme/Bundle/*Bundle/Tests</directory>
812-
</exclude>
813-
</whitelist>
814-
</filter>
823+
<!-- app/phpunit.xml.dist -->
824+
<phpunit>
825+
<!-- ... -->
826+
<filter>
827+
<whitelist>
828+
<!-- ... -->
829+
<directory>../lib</directory>
830+
<exclude>
831+
<!-- ... -->
832+
<directory>../lib/tests</directory>
833+
</exclude>
834+
</whitelist>
835+
</filter>
836+
<!-- ... --->
837+
</phpunit>
815838
816839
Learn more
817840
----------

0 commit comments

Comments
 (0)