mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
docs: add software-testing.mdx
This commit is contained in:
@@ -56,6 +56,7 @@ export default defineConfig({
|
|||||||
items: [
|
items: [
|
||||||
{slug: 'developing/technical-stack'},
|
{slug: 'developing/technical-stack'},
|
||||||
{slug: 'developing/implementing-new-provider'},
|
{slug: 'developing/implementing-new-provider'},
|
||||||
|
{slug: 'developing/software-testing'},
|
||||||
{slug: 'developing/translation'},
|
{slug: 'developing/translation'},
|
||||||
{label: 'Contributing', autogenerate: {directory: 'developing/contributing'}, translations: {fr: 'Contribuer'}}
|
{label: 'Contributing', autogenerate: {directory: 'developing/contributing'}, translations: {fr: 'Contribuer'}}
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ In this section, you’ll implement the logic required to interact with the new
|
|||||||
- Dto.Connector
|
- Dto.Connector
|
||||||
- DefaultProviderDto.php default DTO, which will also be used
|
- DefaultProviderDto.php default DTO, which will also be used
|
||||||
- **MySuperRegistrarProviderDto.php** your new DTO class
|
- **MySuperRegistrarProviderDto.php** your new DTO class
|
||||||
|
- ...
|
||||||
</FileTree>
|
</FileTree>
|
||||||
|
|
||||||
1. Add the necessary class properties and assertions.
|
1. Add the necessary class properties and assertions.
|
||||||
@@ -53,6 +54,7 @@ In this section, you’ll implement the logic required to interact with the new
|
|||||||
- Provider
|
- Provider
|
||||||
- AbstractProvider.php defines the signature of methods
|
- AbstractProvider.php defines the signature of methods
|
||||||
- **MySuperRegistrarProvider.php** your new Provider
|
- **MySuperRegistrarProvider.php** your new Provider
|
||||||
|
- ...
|
||||||
</FileTree>
|
</FileTree>
|
||||||
|
|
||||||
1. The class must extend `AbstractProvider`.
|
1. The class must extend `AbstractProvider`.
|
||||||
@@ -142,6 +144,7 @@ In this section, you’ll implement the logic required to interact with the new
|
|||||||
</Steps>
|
</Steps>
|
||||||
|
|
||||||
**Well done!** 🎉
|
**Well done!** 🎉
|
||||||
|
|
||||||
You have now completed the Backend implementation.
|
You have now completed the Backend implementation.
|
||||||
Let’s continue with the Frontend! 🚀
|
Let’s continue with the Frontend! 🚀
|
||||||
|
|
||||||
@@ -156,6 +159,7 @@ Let’s continue with the Frontend! 🚀
|
|||||||
- forms
|
- forms
|
||||||
- DefaultConnectorFormItems.tsx fields shared by all
|
- DefaultConnectorFormItems.tsx fields shared by all
|
||||||
- **MySuperRegistrarConnectorForm.tsx**
|
- **MySuperRegistrarConnectorForm.tsx**
|
||||||
|
- ...
|
||||||
</FileTree>
|
</FileTree>
|
||||||
|
|
||||||
1. Add the fields corresponding to the DTO you created earlier.
|
1. Add the fields corresponding to the DTO you created earlier.
|
||||||
@@ -185,6 +189,7 @@ Let’s continue with the Frontend! 🚀
|
|||||||
</Steps>
|
</Steps>
|
||||||
|
|
||||||
**Great job!** 🎉
|
**Great job!** 🎉
|
||||||
|
|
||||||
Your Frontend implementation is now complete.
|
Your Frontend implementation is now complete.
|
||||||
|
|
||||||
## Testing
|
## Testing
|
||||||
@@ -219,4 +224,6 @@ Your Frontend implementation is now complete.
|
|||||||
Consider enabling code coverage to identify executed sections.
|
Consider enabling code coverage to identify executed sections.
|
||||||
</Steps>
|
</Steps>
|
||||||
|
|
||||||
That's it! You’ve now finished implementing a new Provider. ✨
|
That's it!
|
||||||
|
|
||||||
|
You’ve now finished implementing a new Provider. ✨
|
||||||
|
|||||||
104
docs/src/content/docs/en/developing/software-testing.mdx
Normal file
104
docs/src/content/docs/en/developing/software-testing.mdx
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
---
|
||||||
|
title: Software Testing
|
||||||
|
description: Discover how to launch and write unit and integration tests for this project using PHPUnit and a test database.
|
||||||
|
---
|
||||||
|
import {FileTree, LinkCard, Steps} from "@astrojs/starlight/components"
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
Before proceeding, note that the first command drops the test database if it exists to ensure a clean testing environment.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
php bin/console doctrine:database:drop --env=test --force
|
||||||
|
```
|
||||||
|
|
||||||
|
### Configure the test environment
|
||||||
|
|
||||||
|
<Steps>
|
||||||
|
1. Create a test database
|
||||||
|
```shell
|
||||||
|
php bin/console doctrine:database:create --env=test
|
||||||
|
```
|
||||||
|
This command will create a blank database, suffixed with `_test` so as not to interfere with your development database.
|
||||||
|
|
||||||
|
1. Run the database migrations
|
||||||
|
```shell
|
||||||
|
php bin/console doctrine:migrations:migrate --env=test
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Configure the specific environment variables for the tests
|
||||||
|
```shell
|
||||||
|
cp .env.test .env.test.local
|
||||||
|
```
|
||||||
|
This file is ignored by version control and lets you configure credentials or secrets required for certain integration tests.
|
||||||
|
</Steps>
|
||||||
|
|
||||||
|
### Run the tests with PHPUnit
|
||||||
|
|
||||||
|
This project uses the [PHPUnit framework](https://phpunit.de/documentation.html) for writing and running tests.
|
||||||
|
It is a good idea to read the [Symfony documentation specific to testing](https://symfony.com/doc/current/testing.html) before starting.
|
||||||
|
|
||||||
|
To run the tests, execute the following command and observe the results.
|
||||||
|
```shell
|
||||||
|
php vendor/bin/phpunit
|
||||||
|
```
|
||||||
|
|
||||||
|
:::tip{icon="heart"}
|
||||||
|
Depending 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.
|
||||||
|
|
||||||
|
```text /D+(S)/ "Skipped: 1"
|
||||||
|
PHPUnit 10.5.58 by Sebastian Bergmann and contributors.
|
||||||
|
|
||||||
|
Runtime: PHP 8.4.15
|
||||||
|
Configuration: /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.
|
||||||
|
|
||||||
|
<FileTree>
|
||||||
|
- domain-watchdog
|
||||||
|
- .env.test
|
||||||
|
- **.env.test.local**
|
||||||
|
- ...
|
||||||
|
</FileTree>
|
||||||
|
|
||||||
|
|
||||||
|
## Write new tests
|
||||||
|
|
||||||
|
All tests should be placed under `tests/` and follow PHPUnit’s naming conventions (`*Test.php`).
|
||||||
|
Ideally, every new code change proposal (via Pull Requests) **MUST** be accompanied by tests related to those changes.
|
||||||
|
Please refer to the Contributing section for more information on the contribution guidelines.
|
||||||
|
|
||||||
|
<LinkCard title="Create a Pull Request" description="Instructions for submitting pull requests" href="/en/developing/contributing/pull-requests" />
|
||||||
|
|
||||||
|
This is particularly important for anything related to the logic (i.e., the algorithms) of this project.
|
||||||
|
|
||||||
|
However, if you are not familiar with writing software tests, feel free to propose changes, and other contributors can take over to ensure your contribution is compliant.
|
||||||
|
|
||||||
|
|
||||||
|
### Writing tests for a new Provider
|
||||||
|
|
||||||
|
The procedure for writing a specific test for a new provider is described on the dedicated page referenced below.
|
||||||
|
|
||||||
|
<LinkCard title="Testing a new Provider" description="Follow these steps to test your implementation of a new Provider" href="/en/developing/implementing-new-provider/#testing" />
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
---
|
|
||||||
title: Software Testing
|
|
||||||
description: Discover how to launch and write unit and integration tests for this project using PHPUnit and a test database.
|
|
||||||
draft: true
|
|
||||||
---
|
|
||||||
Reference in New Issue
Block a user