Skip to content

PHPUnit Backend Testing

The Symfony backend uses PHPUnit for unit tests against entities, mappers, DTOs, and service/orchestrator logic. Tests run against an isolated SQLite test database configured in backend/.env.test.

Test Directory Structure

plaintext
backend/tests/
├── Unit/
│   ├── Entity/              # Doctrine entity behavior
│   ├── Enum/                # Enum helpers
│   ├── DTO/                 # Request/response DTOs
│   ├── Mapper/              # Entity ↔ DTO mappers
│   ├── ValueObject/         # Content extraction value objects
│   └── Service/             # Domain services and orchestrators
│       ├── CategoryServiceTest.php
│       ├── Orchestrator/    # KnowledgeOrchestrator, DigestOrchestrator
│       ├── Digest/          # Scheduler, formatter, distribution
│       ├── Content/         # HTML extraction
│       └── Slack/           # Digest delivery
└── bootstrap.php

There are no HTTP controller integration tests in the repository; API behavior is covered by Playwright E2E tests.

Running the Tests

bash
cd backend
./vendor/bin/phpunit

Run a subset

bash
# All entity tests
./vendor/bin/phpunit tests/Unit/Entity

# Single orchestrator
./vendor/bin/phpunit tests/Unit/Service/Orchestrator/KnowledgeOrchestratorTest.php

Coverage

bash
./vendor/bin/phpunit --coverage-html coverage

Open backend/coverage/index.html in a browser.

Database Reset

If migrations or schema drift cause failures:

bash
cd backend
php bin/console doctrine:database:drop --force --env=test
php bin/console doctrine:database:create --env=test
php bin/console doctrine:schema:create --env=test

CI

Backend checks run in .github/workflows/php-checks.yml:

  • PHP CS Fixer (dry-run)
  • PHPStan
  • PHPUnit