From 95cdcf643d7c9b21d1d2df359339cff64ec2a76c Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Wed, 19 Feb 2025 15:58:03 +0100 Subject: [PATCH] [Testing] Reorganize the introduction of some articles --- testing.rst | 60 ++++++++++++++++++++++-------------------- testing/end_to_end.rst | 44 +++++++++++++------------------ 2 files changed, 50 insertions(+), 54 deletions(-) diff --git a/testing.rst b/testing.rst index 4e719bc23d5..f786a01a83e 100644 --- a/testing.rst +++ b/testing.rst @@ -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``): @@ -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 ---------- @@ -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 diff --git a/testing/end_to_end.rst b/testing/end_to_end.rst index 8a624ae884e..bb4a316f347 100644 --- a/testing/end_to_end.rst +++ b/testing/end_to_end.rst @@ -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 `, 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 ~~~~~~~~~~~~~~~~~~~~~~