Le Rocher Académie uses PHPUnit for comprehensive testing coverage.
tests/
├── Smoke Test.php # Smoke tests for all public routes
├── RegistrationFunctionalTest.php # Registration flow tests
└── (additional functional tests)
docker compose exec php bin/phpunitdocker compose exec php bin/phpunit tests/SmokeTest.phpdocker compose exec php bin/phpunit --coverage-html var/coverageVerify all pages load without errors:
// tests/SmokeTest.php
#[DataProvider('providePublicUrls')]
public function testPageIsSuccessful(string $url): void
{
$client = static::createClient();
$client->request('GET', $url);
$this->assertResponseIsSuccessful();
}Test complete user flows:
// tests/RegistrationFunctionalTest.php
public function testRegistration(): void
{
$client = static::createClient();
$crawler = $client->request('GET', '/register');
$form = $crawler->filter('button[type="submit"]')->form();
// Fill form and submit
// Assert user created, email sent, etc.
}Test individual components in isolation (add as needed).
Tests use a separate app_test database configured in .env.test:
DATABASE_URL="postgresql://app:!ChangeMe!@database:5432/app_test"
# Create test database
docker compose exec database createdb -U app app_test
# Run migrations
docker compose exec php bin/console doctrine:migrations:migrate --env=test
# Load fixtures
docker compose exec php bin/console doctrine:fixtures:load --env=testtest*prefix for test methods- Descriptive names:
testUserCanRegisterWithValidData()
Common assertions:
$this->assertResponseIsSuccessful();
$this->assertSelectorTextContains('h1', 'Welcome');
$this->assertResponseRedirects('/dashboard');
$this->assertEmailCount(1);Use data providers for multiple test cases:
public static function provideInvalidEmails(): \Generator
{
yield ['invalid'];
yield ['@example.com'];
yield ['user@'];
}
#[DataProvider('provideInvalidEmails')]
public function testInvalidEmailRejected(string $email): void
{
// Test logic
}- Isolate Tests: Each test should be independent
- Clean Database: Use transactions or reload fixtures
- Test Edge Cases: Not just happy paths
- Mock External Services: Don't call real APIs in tests
- Fast Tests: Keep tests quick to encourage frequent running
Tests run automatically on:
- Pull requests
- Commits to main branch
- Before deployment
- Minimum: 70% code coverage
- Target: 80%+ coverage
- Critical paths: 100% coverage (auth, payment)
docker compose exec php bin/phpunit --verbosedocker compose exec php bin/phpunit --filter testRegistrationXDEBUG_MODE=coverage docker compose exec php bin/phpunit- Review Development Guide
- Understand Architecture
- See Contributing Guide