Skip to content

Latest commit

 

History

History
64 lines (45 loc) · 2.55 KB

tests.md

File metadata and controls

64 lines (45 loc) · 2.55 KB

Tests

Tests are written using PHPUnit.

Writing functional tests

Writing & updating functional tests should not be a tedious task for the developer. That's why one of the practice we use in several projects in order to ease this is using expectations files and auto-updated expectations with results.

An expectation file is a file with a dumped result from a test case. Results refers here to various things generated by your application to compare, depending on the nature of the tested feature.

Note This practice is also commonly known as « Snapshot Testing »

Generating/Updating dumps of the expectations

When writing your functional test, or when updating the application, you might need to change the .dump, .json, ... files containing your expectations.
You can automatically re-generate these expectations using UPDATE_EXPECTATIONS=1 (or UP=1) in front of the phpunit command line:

UP=1 bin/phpunit --filter=YourTestClass::yourTestCaseMethod

It's recommended to only use this env var with a proper filter scoping the test cases that are supposed to be affected only.

Warning: Don't blindly commit anything after that! Check the diff!!

Debugging tests

Debugging functional tests might not always be easy, as most of the application is like a black box at this point and information about the error might not be in the response, or difficult to find/reason about from generated HTML response.

You need first to lunch your test into a new symfony server with :

make serve@test

If a server is already running, stop it and rerun : make serve.docker+detached.

Hence, the easiest way to debug such tests is to directly access the application in a web context and inspect the Symfony Web Profiler at http://172.0.0.1:63290/_profiler/ to directly access the last collected request.

Note some tests might not be executed in debug mode, hence are not collected by the profiler.
Use APP_DEBUG=1 bin/phpunit --filter=YourTestClass::yourTestCaseMethod to force execute your test in debug mode, so you can inspect it in the web profiler.

Deprecations

Tests are configured to fail whenever a deprecation occurs in the application code or directly using a deprecated vendor code path.

Some deprecations are ignored on purpose, using Symfony's PHPUnit Bridge baseline feature. Update the baseline by temporary using UPDATE_DEPRECATIONS_BASELINE=true in your .env.test.local or:

make test.update-baseline