mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-22 07:33:50 +00:00
Resolve "Notification: envoi à des groupes utilisateurs"
This commit is contained in:
@@ -185,14 +185,57 @@ When we need to use a DateTime or DateTimeImmutable that need to express "now",
|
||||
`Symfony\Component\Clock\ClockInterface`, where possible. This is usually not possible in doctrine entities,
|
||||
where injection does not work when restoring an entity from database, but usually possible in services.
|
||||
|
||||
In test, we use `\Symfony\Component\Clock\MockClock` which is an implementation of `Symfony\Component\Clock\ClockInterface`
|
||||
where we have full and easy control of the date.
|
||||
|
||||
### Testing Information
|
||||
|
||||
The project uses PHPUnit for testing. Each bundle has its own test suite, and there's also a global test suite at the root level.
|
||||
|
||||
#### Use of mock in tests
|
||||
|
||||
##### General mocking
|
||||
|
||||
For creating mock, we prefer using prophecy (library phpspec/prophecy).
|
||||
|
||||
##### Useful helpers and tips that avoid create a mock
|
||||
|
||||
Some notable implementations that are tests helper, and avoid to create a mock:
|
||||
|
||||
- `\Psr\Log\NullLogger`, an implementation of `\Psr\Log\LoggerInterface`;
|
||||
- `\Symfony\Component\Clock\MockClock`, an implementation of `Symfony\Component\Clock\ClockInterface` (already mentioned above);
|
||||
- `\Symfony\Component\HttpClient\MockHttpClient`, an implementation of `\Symfony\Contracts\HttpClient\HttpClientInterface`;
|
||||
- When using `\Symfony\Component\Mailer\MailerInterface`, we can create the mock with "InMemoryTransport":
|
||||
|
||||
```php
|
||||
use Symfony\Component\Mailer\Transport\InMemoryTransport;
|
||||
use \Symfony\Component\Mailer\Mailer;
|
||||
|
||||
$transport = new InMemoryTransport();
|
||||
$mailer = new Mailer($transport);
|
||||
|
||||
// After sending:
|
||||
$messages = $transport->getSent(); // array of SentMessage
|
||||
```
|
||||
- When using `\Symfony\Contracts\EventDispatcher\EventDispatcherInterface`, we can use directly an instance of `\Symfony\Component\EventDispatcher\EventDispatcher`;
|
||||
|
||||
##### When we prefer not creating a mock
|
||||
|
||||
- When we use Doctrine Entities related to the project, we prefer not to use a mock: we instantiate them directly (unless it requires too much code to write);
|
||||
|
||||
##### Mocking final and readonly classes
|
||||
|
||||
Classes marked as final can't be mocked. To avoid that, either:
|
||||
|
||||
- we remove the `final` keyword from the class;
|
||||
- we extract an interface from the final class.
|
||||
|
||||
This must be a decision made by a human, not by an AI. Every AI task must abort with an explicit message in that case.
|
||||
|
||||
#### Running Tests
|
||||
|
||||
The tests are run from the project's root (not from the bundle's root).
|
||||
|
||||
```bash
|
||||
# Run all tests
|
||||
vendor/bin/phpunit
|
||||
|
Reference in New Issue
Block a user