Skip to content
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

Improve and simplify the contributing instructions about tests #5564

Closed
Closed
Changes from all 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
89 changes: 22 additions & 67 deletions contributing/code/tests.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,32 @@
Running Symfony Tests
=====================

Before submitting a :doc:`patch <patches>` for inclusion, you need to run the
Symfony test suite to check that you have not broken anything.
The Symfony project uses a third-party service which automatically runs tests
for any submitted :doc:`patch <patches>`. If the new code breaks any test,
the pull request will show an error message with a link to the full error details.

PHPUnit
-------
In any case, it's a good practice to run tests locally before submitting a
:doc:`patch <patches>` for inclusion, to check that you have not broken anything.

To run the Symfony test suite, `install PHPUnit`_ 4.2 (or later) first.
.. _phpunit:
.. _dependencies_optional:

Dependencies (optional)
-----------------------
Before Running the Tests
------------------------

To run the entire test suite, including tests that depend on external
dependencies, Symfony needs to be able to autoload them. By default, they are
autoloaded from ``vendor/`` under the main root directory (see
``autoload.php.dist``).

The test suite needs the following third-party libraries:

* Doctrine
* Swift Mailer
* Twig
* Monolog

To install them all, use `Composer`_:

Step 1: :doc:`Install Composer globally </cookbook/composer>`

Step 2: Install vendors.
To run the Symfony test suite, `install PHPUnit`_ 4.2 (or later) first. Then,
install the external dependencies used during the tests, such as Doctrine, Twig
and Monolog. To do so, :doc:`install Composer </cookbook/composer>` and execute
the following:

.. code-block:: bash

$ composer install

.. note::

Note that the script takes some time to finish.
.. _running:

After installation, you can update the vendors to their latest version with
the follow command:

.. code-block:: bash

$ composer update

Running
-------

First, update the vendors (see above).
Running the Tests
-----------------

Then, run the test suite from the Symfony root directory with the following
command:
Expand All @@ -59,40 +37,17 @@ command:

$ phpunit

The output should display ``OK``. If not, you need to figure out what's going on
and if the tests are broken because of your modifications.
The output should display ``OK``. If not, read the reported errors to figure out
what's going on and if the tests are broken because of the new code.

.. tip::

If you want to test a single component type its path after the ``phpunit``
command, e.g.:
The entire Symfony suite can take up to several minutes to complete. If you
want to test a single component, type its path after the ``phpunit`` command,
e.g.:

.. code-block:: bash

$ phpunit src/Symfony/Component/Finder/

.. tip::

Run the test suite before applying your modifications to check that they
run fine on your configuration.

Code Coverage
-------------

If you add a new feature, you also need to check the code coverage by using
the ``coverage-html`` option:

.. code-block:: bash

$ phpunit --coverage-html=cov/

Check the code coverage by opening the generated ``cov/index.html`` page in a
browser.

.. tip::

The code coverage only works if you have Xdebug enabled and all
dependencies installed.

.. _install PHPUnit: https://phpunit.de/manual/current/en/installation.html
.. _`Composer`: https://getcomposer.org/
.. _`install PHPUnit`: https://phpunit.de/manual/current/en/installation.html