Skip to content

[Testing] Reorganize the introduction of some articles #20670

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
Feb 20, 2025
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
60 changes: 31 additions & 29 deletions testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,38 @@ Whenever you write a new line of code, you also potentially add new bugs.
To build better and more reliable applications, you should test your code
using both functional and unit tests.

.. _testing-installation:
Symfony integrates with an independent library called `PHPUnit`_ to give you a
rich testing framework. This article covers the PHPUnit basics you'll need to
write Symfony tests. To learn everything about PHPUnit and its features, read
the `official PHPUnit documentation`_.

Types of Tests
--------------

There are many types of automated tests and precise definitions often
differ from project to project. In Symfony, the following definitions are
used. If you have learned something different, that is not necessarily
wrong, just different from what the Symfony documentation is using.

`Unit Tests`_
These tests ensure that *individual* units of source code (e.g. a single
class) behave as intended.

`Integration Tests`_
These tests test a combination of classes and commonly interact with
Symfony's service container. These tests do not yet cover the fully
working application, those are called *Application tests*.

`Application Tests`_
Application tests (also known as functional tests) test the behavior of a
complete application. They make HTTP requests (both real and simulated ones)
and test that the response is as expected.

The PHPUnit Testing Framework
-----------------------------
.. _testing-installation:
.. _the-phpunit-testing-framework:

Symfony integrates with an independent library called `PHPUnit`_ to give
you a rich testing framework. This article won't cover PHPUnit itself,
which has its own excellent `documentation`_.
Installation
------------

Before creating your first test, install ``symfony/test-pack``, which installs
some other packages needed for testing (such as ``phpunit/phpunit``):
Expand Down Expand Up @@ -44,28 +68,6 @@ your test into multiple "test suites").
missing, you can try running the recipe again using
``composer recipes:install phpunit/phpunit --force -v``.

Types of Tests
--------------

There are many types of automated tests and precise definitions often
differ from project to project. In Symfony, the following definitions are
used. If you have learned something different, that is not necessarily
wrong, just different from what the Symfony documentation is using.

`Unit Tests`_
These tests ensure that *individual* units of source code (e.g. a single
class) behave as intended.

`Integration Tests`_
These tests test a combination of classes and commonly interact with
Symfony's service container. These tests do not yet cover the fully
working application, those are called *Application tests*.

`Application Tests`_
Application tests test the behavior of a complete application. They
make HTTP requests (both real and simulated ones) and test that the
response is as expected.

Unit Tests
----------

Expand Down Expand Up @@ -1193,7 +1195,7 @@ Learn more
/components/css_selector

.. _`PHPUnit`: https://phpunit.de/
.. _`documentation`: https://docs.phpunit.de/
.. _`official PHPUnit documentation`: https://docs.phpunit.de/
.. _`Writing Tests for PHPUnit`: https://docs.phpunit.de/en/10.5/writing-tests-for-phpunit.html
.. _`PHPUnit documentation`: https://docs.phpunit.de/en/10.5/configuration.html
.. _`unit test`: https://en.wikipedia.org/wiki/Unit_testing
Expand Down
44 changes: 19 additions & 25 deletions testing/end_to_end.rst
Original file line number Diff line number Diff line change
@@ -1,41 +1,35 @@
End-to-End Testing
==================

The Panther component allows to drive a real web browser with PHP to create
end-to-end tests.
End-to-end tests simulate how real users interact with your application through
a browser. They focus on verifying your user interface and the outcomes of user
actions (like confirming that clicking a button sends an email).

Unlike :ref:`application tests <functional-tests>`, these tests run in a real
browser that can work in headless mode (without a graphical interface) for CI
environments or with a graphical interface for debugging.

Symfony provides a component called **Panther** to run end-to-end tests. Panther
lets you run tests in a real browser and offers unique features not available in
other test types:

* Taking screenshots at any point during the test;
* Executing JavaScript on your pages;
* Supporting everything Chrome or Firefox does;
* Simpler testing of real-time applications (e.g. WebSockets, Server-Sent Events with Mercure).

Installation
------------

Before creating and running your first end-to-end tests, run the following command
to install the needed dependencies:

.. code-block:: terminal

$ composer require symfony/panther

.. include:: /components/require_autoload.rst.inc

Introduction
------------

End to end tests are a special type of application tests that
simulate a real user interacting with your application. They are
typically used to test the user interface (UI) of your application
and the effects of these interactions (e.g. when I click on this button, a mail
must be sent). The difference with functional tests detailed above is
that End-to-End tests use a real browser instead of a simulated one. This
browser can run in headless mode (without a graphical interface) or not.
The first option is convenient for running tests in a Continuous Integration
(CI), while the second one is useful for debugging purpose.

This is the purpose of Panther, a component that provides a real browser
to run your tests. Here are a few things that make Panther special, compared
to other testing tools provided by Symfony:

* Possibility to take screenshots of the browser at any time during the test
* The JavaScript code contained in webpages is executed
* Panther supports everything that Chrome (or Firefox) implements
* Convenient way to test real-time applications (e.g. WebSockets, Server-Sent Events
with Mercure, etc.)

Installing Web Drivers
~~~~~~~~~~~~~~~~~~~~~~

Expand Down