Updated: 10 December 2024
See https://symfony.com/doc/current/testing.html
Unit Tests
- Test a Class.
- Test a method in a Class.
- Equivalent to standard PHPUnit unit tests.
- Does not hit the database – use mocks instead.
Integration Tests
- Tests a larger part of the app than Unit tests e.g. a combination of Services.
- Might use the Kernel to fetch services from the dependency injection container.
- Integration test classes should extend
KernelTestCase
. - May involve mocking of Class dependencies.
- May interact with a test database, populated via fixtures.
Application Tests
- Checks integration of all layers of the app, from routing to views, excluding on page javascript.
- Has a specific workflow:
- Make request.
- Interact with page.
- Test response.
- Probably won’t involve mocking dependencies.
- Probably will interact with a test database.
- Integration test classes should extend
WebTestCase
.
End to End Tests
- Test the application as a whole, including on page JavaScript code.
- Involves a real browser instead of the test client.
- See Symfony Panther component.
The output of make:test
supplies a useful summary
root@5b8333e33939:/var/www/html# bin/console make:test
Which test type would you like?:
[TestCase ] basic PHPUnit tests
[KernelTestCase ] basic tests that have access to Symfony services
[WebTestCase ] to run browser-like scenarios, but that do not execute JavaScript code
[ApiTestCase ] to run API-oriented scenarios
[PantherTestCase] to run e2e scenarios, using a real-browser or HTTP client and a real web server