Skip to content

[Testing] Fix phpunit test dir paths #3343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 13, 2014
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 58 additions & 29 deletions book/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ it has its own excellent `documentation`_.
needed to test the Symfony core code itself.

Each test - whether it's a unit test or a functional test - is a PHP class
that should live in the `Tests/` subdirectory of your bundles. If you follow
that should live in the ``Tests/`` subdirectory of your bundles. If you follow
this rule, then you can run all of your application's tests with the following
command:

Expand Down Expand Up @@ -686,7 +686,7 @@ their type::
Testing Configuration
---------------------

The Client used by functional tests creates a Kernel that runs in a special
The client used by functional tests creates a Kernel that runs in a special
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Client, it refers to an object, just like Kernel

``test`` environment. Since Symfony loads the ``app/config/config_test.yml``
in the ``test`` environment, you can tweak any of your application's settings
specifically for testing.
Expand Down Expand Up @@ -766,47 +766,76 @@ PHPUnit Configuration
~~~~~~~~~~~~~~~~~~~~~

Each application has its own PHPUnit configuration, stored in the
``phpunit.xml.dist`` file. You can edit this file to change the defaults or
create a ``phpunit.xml`` file to tweak the configuration for your local machine.
``app/phpunit.xml.dist`` file. You can edit this file to change the defaults or
create a ``app/phpunit.xml`` file to setup a configuration for your local
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[...] an app/phpunit.xml file [...]

machine only.

.. tip::

Store the ``phpunit.xml.dist`` file in your code repository, and ignore the
Store the ``phpunit.xml.dist`` file in your code repository and ignore the
``phpunit.xml`` file.

By default, only the tests stored in "standard" bundles are run by the
``phpunit`` command (standard being tests in the ``src/*/Bundle/Tests`` or
``src/*/Bundle/*Bundle/Tests`` directories) But you can easily add more
directories. For instance, the following configuration adds the tests from
the installed third-party bundles:
By default, only the tests from your own custom bundles stored in the standard
directories ``src/*/*Bundle/Tests`` or ``src/*/Bundle/*Bundle/Tests`` are run
by the ``phpunit`` command:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[...] command, as configured in the phpunit.xml.dist file:


.. code-block:: xml

<!-- hello/phpunit.xml.dist -->
<testsuites>
<testsuite name="Project Test Suite">
<directory>../src/*/*Bundle/Tests</directory>
<directory>../src/Acme/Bundle/*Bundle/Tests</directory>
</testsuite>
</testsuites>
<!-- app/phpunit.xml.dist -->

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this line

<phpunit>
<!-- ... -->
<testsuites>
<testsuite name="Project Test Suite">
<directory>../src/*/*Bundle/Tests</directory>
<directory>../src/*/Bundle/*Bundle/Tests</directory>
</testsuite>
</testsuites>
<!-- ... -->
</phpunit>

But you can easily add more directories. For instance, the following
configuration adds tests from a custom ``lib/tests`` directory:

.. code-block:: xml

<!-- app/phpunit.xml.dist -->

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this line

<phpunit>
<!-- ... -->
<testsuites>
<testsuite name="Project Test Suite">
<!-- ... --->
<directory>../lib/tests</directory>
</testsuite>
</testsuites>
<!-- ... --->
</phpunit>

To include other directories in the code coverage, also edit the ``<filter>``
section:

.. code-block:: xml

<!-- ... -->
<filter>
<whitelist>
<directory>../src</directory>
<exclude>
<directory>../src/*/*Bundle/Resources</directory>
<directory>../src/*/*Bundle/Tests</directory>
<directory>../src/Acme/Bundle/*Bundle/Resources</directory>
<directory>../src/Acme/Bundle/*Bundle/Tests</directory>
</exclude>
</whitelist>
</filter>
<!-- app/phpunit.xml.dist -->

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this line

<phpunit>
<!-- ... -->
<filter>
<whitelist>
<directory>../src</directory>
<directory>../lib</directory>
<exclude>
<directory>../src/*/*Bundle/Resources</directory>
<directory>../src/*/*Bundle/Tests</directory>
<directory>../src/*/Bundle/*Bundle/Resources</directory>
<directory>../src/*/Bundle/*Bundle/Tests</directory>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe just fold all not changed lines?

<whitelist>
    <!-- ... -->
    <directory>../lib</directory>
    <exclude>
        <!-- ... -->
        <directory>../lib/tests</directory>
    </exclude>
</whitelist>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. Thought about this, too.

<directory>../lib/tests</directory>
</exclude>
</whitelist>
</filter>
<!-- ... --->
</phpunit>

Learn more
----------
Expand Down