Updated: 23 November 2024
Symfony
Symfony testing
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
Symfony console
Updated: 23 November 2024
Generate a migration by comparing your current database to your mapping information
bin/console doctrine:migrations:diff
Create a new migration based on database changes
bin/console make:migration
List all configured routes in application
bin/console debug:router
Display environment variables used in the container
bin/console debug:container --env-vars
Dump the default configuration for security
bin/console config:dump-reference security
Symfony – scaffold app from existing database
Updated: 04 April 2024
Prepare for a new run
rm -r src/Entity/*
rm -r src/Form/*
rm -r src/Controller/*
rm -r src/Repository/*
rm -r templates/*
Copy in a backup of base twig template
cp base.html.twig templates/
Generate entities from an existing database
bin/console doctrine:mapping:import "App\Entity" annotation --path=src/Entity
bin/console make:entity --regenerate App
Make CRUD for each new entity
bin/console make:crud MyEntity
bin/console make:crud AnotherEntity
...
Adjust file permissions
sudo chown -R chris:chris templates/
sudo chown -R chris:chris src/Entity/
sudo chown -R chris:chris src/Controller/
sudo chown -R chris:chris src/Form/
Now, sql insert data fixtures
...