Skip to content

Migrating Tests topics to Symfony Flex structure #8577

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 1 commit into from
Nov 5, 2017
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions best_practices/tests.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ functional tests, you can quickly spot any big errors before you deploy them:

A functional test can be as easy as this::

// tests/AppBundle/ApplicationAvailabilityFunctionalTest.php
namespace Tests\AppBundle;
// tests/ApplicationAvailabilityFunctionalTest.php
namespace App\Tests;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

Expand Down
24 changes: 12 additions & 12 deletions testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ called ``Calculator`` in the ``Util/`` directory of the app bundle::
}
}

To test this, create a ``CalculatorTest`` file in the ``tests/AppBundle/Util`` directory
To test this, create a ``CalculatorTest`` file in the ``tests/Util`` directory
of your application::

// tests/Util/CalculatorTest.php
Expand All @@ -85,9 +85,9 @@ of your application::

.. note::

By convention, the ``tests/AppBundle`` directory should replicate the directory
By convention, the ``tests/`` directory should replicate the directory
of your bundle for unit tests. So, if you're testing a class in the
``src/Util/`` directory, put the test in the ``tests/AppBundle/Util/``
``src/Util/`` directory, put the test in the ``tests/Util/``
directory.

Just like in your real application - autoloading is automatically enabled
Expand All @@ -102,13 +102,13 @@ Running tests for a given file or directory is also very easy:
$ phpunit

# run all tests in the Util directory
$ phpunit tests/AppBundle/Util
$ phpunit tests/Util

# run tests for the Calculator class
$ phpunit tests/AppBundle/Util/CalculatorTest.php
$ phpunit tests/Util/CalculatorTest.php

# run all tests for the entire Bundle
$ phpunit tests/AppBundle/
$ phpunit tests/

.. index::
single: Tests; Functional tests
Expand All @@ -129,7 +129,7 @@ tests as far as PHPUnit is concerned, but they have a very specific workflow:
Your First Functional Test
~~~~~~~~~~~~~~~~~~~~~~~~~~

Functional tests are simple PHP files that typically live in the ``tests/AppBundle/Controller``
Functional tests are simple PHP files that typically live in the ``tests/Controller``
directory for your bundle. If you want to test the pages handled by your
``PostController`` class, start by creating a new ``PostControllerTest.php``
file that extends a special ``WebTestCase`` class.
Expand Down Expand Up @@ -757,7 +757,7 @@ Testing Configuration
---------------------

The Client used by functional tests creates a Kernel that runs in a special
``test`` environment. Since Symfony loads the ``app/config/config_test.yml``
``test`` environment. Since Symfony loads the ``config/packages/test/*.yaml``
in the ``test`` environment, you can tweak any of your application's settings
specifically for testing.

Expand All @@ -769,15 +769,15 @@ configuration option:

.. code-block:: yaml

# app/config/config_test.yml
# config/packages/test/swiftmailer.yaml

# ...
swiftmailer:
disable_delivery: true

.. code-block:: xml

<!-- app/config/config_test.xml -->
<!-- config/packages/test/swiftmailer.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Expand All @@ -793,7 +793,7 @@ configuration option:

.. code-block:: php

// app/config/config_test.php
// config/packages/test/swiftmailer.php

// ...
$container->loadFromExtension('swiftmailer', array(
Expand Down Expand Up @@ -847,7 +847,7 @@ only.
Store the ``phpunit.xml.dist`` file in your code repository and ignore
the ``phpunit.xml`` file.

By default, only the tests stored in ``/tests`` are run via the ``phpunit`` command,
By default, only the tests stored in ``tests/`` are run via the ``phpunit`` command,
as configured in the ``phpunit.xml.dist`` file:

.. code-block:: xml
Expand Down