Magento 1.9 – Best Practices for Unit Tests

magento-1.9phpunittestingunit tests

I maintain a Magento 1.9 site with several custom modules. Some of the functionality is business critical and in dire need of some unit tests. E.g. a unit price calculator.

I usually develop in Symfony and would really prefer to somehow use PHPUnit (w/Composer) if that's at all possible.

Some functionality is based on data imported to a several custom database tables so I would prefer to somehow load fixtures.

So I'm looking for the best practice approach to writing some unit tests. I will glady accept tutorials or something similar. Any help is appreciated.

Best Answer

I faced the same problem a while back.

I considered using the Ecomdev PHPUnit module but I find it hard to use and poorly documented (but I still love what Ivan does and his great contribution to the Magento ecosystem).

So, with the help of Vinai, I ended up developping the following test framework module: https://github.com/digitalpianism/testframework

Original purpose was for integration tests but I'm using it for unit tests too. You can see it in action here: https://github.com/digitalpianism/easytoplinks/blob/master/app/code/community/DigitalPianism/EasyToplinks/Test/Unit/Block/Page/Template/LinksTest.php

Regarding fixtures, I'm using transaction rollbacks to avoid creating sample data in database.

Related Topic