Just created hgraca/doctrine-test-db-regeneration-bundle

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:

  1. 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;
  2. 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;
  3. 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.

When to use events

Typically, in a layered architecture, the top layers are aware of the lower layers and start logic in the lower layers. But, the lower layers are not aware of the layers above and can not start logic in the layers above. However, in highly complex situations, the lower layers might need to fire logic in the top layers.

Continue reading “When to use events”

Creating relationships between entities with Symfony2, Doctrine and yml

So I’m starting a new project now, I’ve set up the logger, I’ve set up the mailing, and now it’s time I start to set up the model layer with Doctrine. In Symfony2 you can choose to have the configuration of this layer in xml files, yml files or as annotations directly in the entities classes. Personaly I find xml files too verbose, and annotations put logic in the entities which makes them less readable and if we want to change ORM we will have Doctrine configurations in entities that do not deal with Doctrine, so I prefer to have the configurations in yml files. Symfony has some documentation on how to set this up, but its not complete, as far as I can remember it only has documentation about one to many relationships, but in real life situations we rarely find only those types of relationships in a DB schema, so here I will document how to configure one to one, one to many, many to many and many to many to many relationships.

Continue reading “Creating relationships between entities with Symfony2, Doctrine and yml”

How to set up a proper logger in Symfony2

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”

Exam Enrollments

A Joomla component to allow students to enroll themselves on-line into exams.

It’s made having in mind Portuguese K12 Professional Courses, but its quite generic, so it probably works for other countries/models as well.

The only language is Portuguese, but you are free to translate it, and if you do, please send it to me so I can add it to the package.

You can see it working in the video below (available soon), and you can get it here.

Check out the pictures below.

Application admin
Application admin

Students/Exams list
Students/Exams list

Admin edit options
Admin edit options

Form so a student enrolls in an exam
Form so a student enrolls in an exam

Student checks exams list
Student checks exams list

File Selector

A component to select a file to download using up to 4 selection criteria, in 4 selection drop down menus. I created this in 2008.

I use it in my school website to make the all the final grades available. For example, the user would choose the year, the level and the class he is in, and would download the required pdf file with the class grades. Furthermore, it has a full functional back office to create different document types, that will show in different web pages, and to upload several files at once. When creating the link, you will be able to choose the document type, the page title and if you want to show the downloads count for that document type. Since version 1.0.3 there’s also the option to show the selection menus vertically.

The files download count are also marked, but I don’t show them in the site front end, only in the administrator view. It requires PHP5.

As of version 2.0.0, its designed for Joomla! 1.6.x .

NOTE: I used PHP short tags, so if you have some problems with the component, try following this instructions:
http://www.cyberciti.biz/faq/php-allow-short_open_tag/
If you still have problems, feel free to contact me and I’ll try to help you out. I will solve that issue whenever I make a new version for this.

You can see it working here, and you can get it here.

Check out the pictures below.

File selector
File selector

Main back-end
Main back-end

Creating a new document type
Creating a new document type

Uploading files
Uploading files