One of the things I’m developing a love for with Symfony 2 is how Doctrine, forms and Twig work together in a fairly elegant manner. With a little bit of code and annotations, you can allow Symfony 2 to perform a lot of the heavy lifting and boiler plate code that normally is a pain-in-the-rear to handle. One such aspect in development is the many-to-many relationship mapping and subsequent introduction of that code into forms. Symfony 2 will remove all the painful setup but nailing down the right technique might make you do a little research online. What I would like to do is bring together my way of dealing with this problem into a single article.
While creating a phpunit test against a form for Symfony 2, I encountered an interesting problem that made little sense to me at first (for reference, I was following an example for unit testing form types from the Symfony 2 website). The problem was that the data being submitted appeared to not be mapped correctly, which caused the unit test to fail unexpectedly. Why is that?
I learned that the DoctrineMigrationBundle does not come as part of the default Symfony 2 install and that you must manually install it. The documentation for installing it on the main web site is really an oversimplification of what you’ll have to do on a Mac OS Snow Leopard situation as I discovered. In turn, I decided to post this blog to help others that may encounter similar problems.
Although I gave Ruby on Rails a small try a little while back, I ended up not choosing it as my framework for the moment mostly because I felt that there was a double learning curve in familiarizing myself not only with the Rails framework but Ruby as well. I still would like to give Rails a shot another day but for the moment I want to focus on getting a project completed. Of course, I would like to try something new as well which is why I decided to investigate Symfony 2.