Software Testing
Ce contenu n’est pas encore disponible dans votre langue.
Due to the nature of this project, it is essential to ensure that the logic is properly tested.
For example, it is important to test whether the API calls to the supported Registrars are correctly implemented.
Run the tests
Section titled “Run the tests”Before proceeding, note that the first command drops the test database if it exists to ensure a clean testing environment.
php bin/console doctrine:database:drop --env=test --forceConfigure the test environment
Section titled “Configure the test environment”-
Create a test database
Terminal window php bin/console doctrine:database:create --env=testThis command will create a blank database, suffixed with
_testso as not to interfere with your development database. -
Run the database migrations
Terminal window php bin/console doctrine:migrations:migrate --env=test -
Configure the specific environment variables for the tests
Terminal window cp .env.test .env.test.localThis file is ignored by version control and lets you configure credentials or secrets required for certain integration tests.
Run the tests with PHPUnit
Section titled “Run the tests with PHPUnit”This project uses the PHPUnit framework for writing and running tests. It is a good idea to read the Symfony documentation specific to testing before starting.
To run the tests, execute the following command and observe the results.
php vendor/bin/phpunitDepending on the integrated development environment (IDE) you use, it may have PHPUnit integration. This integration can be very useful for viewing code coverage and helping you interpret test results.
If you choose to run the tests using the command line, you can expect to get a result similar to the one below.
PHPUnit 10.5.58 by Sebastian Bergmann and contributors.
Runtime: PHP 8.4.15Configuration: /home/maelgangloff/Documents/git/domain-watchdog/phpunit.dist.xml
DDDDDDDDDDDDDDDDD.DDDDDD.............DDDDDDDDSDDDDDDDDD 55 / 55 (100%)
Faker seed: 777840
Time: 00:30.381, Memory: 318.50 MB
OK, but there were issues!Tests: 55, Assertions: 86, Deprecations: 26, Skipped: 1.In this example, note that a test has been skipped (the highlighted S in the result above).
This test verifies the purchase of a domain name using a Registrar’s sandbox API.
Because authentication credentials are not set in the environment variables, this test is configured to be skipped.
To configure these variables, please modify the file specific to the test environment.
Répertoiredomain-watchdog
- .env.test
- .env.test.local
- …
Write new tests
Section titled “Write new tests”All tests should be placed under tests/ and follow PHPUnit’s naming conventions (*Test.php).
Ideally, every proposed code change (via Pull Requests) MUST include tests covering the related modifications. Refer to the Contributing section for more details on the guidelines.
This requirement is especially important for any change affecting the project’s logic or algorithms.
If you are not yet familiar with writing tests, you are still welcome to submit your changes. Other contributors can help ensure the necessary tests are added.
Writing tests for a new Provider
Section titled “Writing tests for a new Provider”The procedure for creating tests for a new provider is described on the dedicated page below.