While working on the next post of The Software Architecture Chronicles I ended up creating a little symfony bundle which I called hgraca/doctrine-test-db-regeneration-bundle to generate and regenerate the tests database used by a phpunit tests suite.
It is inspired by some code that Luis Cobucci wrote back in 2017, and it uses the Doctrine fixtures to generate a backup of the tests DB, which is then put in place just before every test method and removed just after every test method.
It has 3 options:
- We can opt to use an existing tests DB backup, if it is available. This saves us the time to generate the DB, but it will not be useful if we want to test queries that are based on time like “select all users created in the last hour” because if the backup is older than 1h our tests will fail;
- We can opt to not put in place a new copy of the DB at the beginning of a test method, so that we can safely use the DAMA\DoctrineTestBundle together with this bundle;
- We can opt to not remove the DB at the end of a test method, so that we can safely use the DAMA\DoctrineTestBundle together with this bundle.
You can check out the bundle here: hgraca/doctrine-test-db-regeneration-bundle
Hope it’s useful for more people and constructive feedback is always welcome.
So I have a DB being created automatically for me using Symfony and Doctrine. Now I want to add some initial data so that I can actually develop some code to use the DB.
We do this by using the doctrine-fixtures-bundle to create classes that will load some data into our tables.
Continue reading “Adding fixtures to the DB using Symfony2 and Doctrine” →
It seems there’s a bug in Symfony, when updating to Monolog Bundle 2.5.0 that causes this if you do not have the ‘spool’ config value set under the swiftmailer configuration.
Continue reading “Symfony bug: ‘dependency on a non-existent service “swiftmailer.transport.real”‘” →
Properly setting up a logging system for your application is essential for its maintainability, debugging and monitoring.
That being said, what we ideally want in a logging system is the following:
- Only log our application messages, don’t log symphony stuff;
- Log to a different file per environment (dev.log, test.log, prod.log);
- Log to the console, when we run the app through the command line. This way we see feedback immediately, we don’t need to have another window open with tail -f dev.log. With this we can also automate the feedback the app gives back tot he user;
- Also log specific jobs to a specific file, so we have a log per job;
- On Production it should also send us an email if something goes wrong.
Continue reading “How to set up a proper logger in Symfony2” →