Welcome to

thirty4 interactive

Just another company blog

Automating symfony application builds

February 7th, 2008 by Damian Hodgkiss

When developing a complex, structured web application proper testing is a very important aspect that is often overlooked. By using unit and functional tests you not only verify the code works as it should, but you are also able to catch things that break during the ongoing development process.

Writing tests alone can often be a tedious task, but it is a task that is well worth the effort. Symfony provides steps to make testing core units and browser output a breeze. You can use unit testing to ensure core functionality of your library classes are working as expected and functional testing to ensure URLs are working as expected. By including a test for every module action you are able to catch anything that breaks as a result to code refactoring and forces an unexpected HTTP return code.

Writing Tests

I will try not to repeat any of the information in the Symfony Book and just provide a basic overview of minimal testing you should be doing.

For each library class you develop, you should have at least one test unit which tests the expected behavior of every public method. This will ensure the foundation of your application works correctly. Each method test should check to ensure the correct behavior, the incorrect behavior and that the correct exception is thrown for a particular action.

To go beyond core behavior testing, you should also verify every action your application exposes works as expected. This means they should all be checked for a valid HTTP 200 response code and should include various other checks where possible. For example a download redirection script should check for a valid redirection. As well as various HTTP checks you can also check the output does not contain various PHP warning messages which don’t always affect the application but should be fixed regardless.

Package Automation

Every application has a different packaging method whether it be create a PEAR package or just compress the directory contents. This task can also be automated by creating the required steps in a task. An example task may run a freeze, create a valid PEAR package.xml, run pear package and unfreeze the project. For flexibility the task should take optional parameters such as version or package filename information.

Nightly Build Automation

Nightly build automation can be accomplished in various ways using something as simple as a shell script in crontab right through to an application like CruiseControl. We prefer to use CruiseControl because it provides flexible scheduling options and comes with a vast array of plugins to provide various actions. While primarily aimed at Java applications, the flexibility of CruiseControl makes it suitable for almost any project.

Depending on your goals, your nightly build automation should go something like checkout trunk from SVN, run unit and functional testing, build a package, upload package, e-mail the results. This allows you to not only have a historical reference of every build, but also gives you early notification of test failures.

Conclusion

Proper testing and development processes are often overlooked by the average PHP developer mindset, but by going that little bit further you can ensure you produce a well developed, well tested application with fewer problems likely to appear when it is published for public consumption.

While test driven development is not required, detailed unit and functional testing in any development process is sure to decrease the likely hood of problems.

Posted in Development |

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

Copyright © 2oo8 by thirty4 interactive