API
note
📣  All commands have to be run in the api service (make api).
Pest#
Pest is a wrapper around PHPUnit.
In the Symfony Boilerplate, we focus on testing the use cases.
Usage#
It executes all tests and display the result and the code coverage in your terminal.
An HTML output is also available under the src/api/coverage folder. Do not hesitate to take a look at it!
You can also run tests per group, for instance:
Configuration#
Most of the configuration occurs in the src/api/phpunit.xml.dist file. Here, we:
- Override some environment variables.
 - Exclude PHP files from code coverage.
 
Good to know#
- We use the 
mysql_testservice as a database; before running tests, the PHP script src/api/tests/bootstrap.php destroys the database, re-creates it, and applies migrations. - A rollback occurs after each test; if you need test data for all tests from a file, you may use the 
beforeEachmethod. See, for instance, the file src/api/tests/UseCase/User/GetUsersTest.php. - The Symfony mailer does not send emails.
 - The 
Storagesdo not send files to theminioservice but use the memory instead. 
Testing a use case#
Let's say you have the following use case:
In the Pest file src/api/tests/UseCase/Foo/CreateFooTest.php, you should focus on testing the creation of a Foo
(violations, etc.).
In other words, do not test the use case CreateBar, as it should have its dedicated test.
note
📣  You must import a use case somewhere in your source code; otherwise Pest (or PHPUnit) will not be able to inject it in your tests.
Behat#
🚧