Testing Agavi: Why Test Isolation Matters

David Zülke » 24 April 2009 » in Open Source Case Studies » 1 Comment

This is an abstract for a chapter from a book on Quality Assurance in PHP Projects.

Agavi is a Model-View-Controller (MVC) framework for PHP that started out as a fork of the popular Mojavi. One of the project's primary goals was to refactor the code to allow for easier testing of various parts of the framework. But even after this refactoring it turned out to be a challenge to test something as complex and coupled as a full-stack framework properly.

One of the major challenges with regard to the testing of Agavi was the isolation of test runs. Agavi is quite flexible in how it handles initialization and re-use of objects. While several facilities in the framework can be reset to their original state, certain parts are hard to reset once they are initialized. A prime example of this is the boostrapping sequence that loads configuration handlers, autoloading definitions, and so forth. Running every test in the same global state was clearly not desired in cases where complex relations needed to be tested, for instance when writing test cases for bugs. Furthermore, Agavi has the concept of "environments" the application runs in ("production", "development-joe", ...) that could, and should, be used for selectively configuring the system for certain testing scenarios. For instance, the framework should be started with the environment testing-ticket1234, which in turn loads certain configuration values needed to reproduce the issue described in ticket #1234.

The key to overcoming these obstacles was the support for isolated test processes added in PHPUnit 3.4. It finally allowed running multiple instances of the framework and an application in isolation, without side-effects and without compromising quality, clarity or readability of either the framework source code or the tests. Other features added in PHPUnit 3.4 such as the support for custom annotations were welcome additions that allowed the Agavi team to greatly simplify the effort needed to control the execution of tests both in userland tests and in tests of the framework itself.

This case study will discuss the challenges and solutions faced in testing both the Agavi framework itself as well as applications built on top of it. The focus is on how PHPUnit 3.4 makes writing and running these test easier and more comfortable.

David Zülke is the CEO of Bitextender GmbH and a core developer of Agavi.

Trackback specific URI for this entry

1 Comment to "Testing Agavi: Why Test Isolation Matters"

Display comments as (Linear | Threaded)
  1. Karsten Deubert
    25/04/2009 at 12:56 Permalink
    There is a small typo in the last paragraph, "Agavei".
    As an Agavi-user, i'm curious about this chapter of the book ;)

    Greetings from germany,
    Karsten

    Reply

0 Trackbacks to "Testing Agavi: Why Test Isolation Matters"

  1. www.logaholic.de 25/04/2009 at 15:03

Add Comment

Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.


Submitted comments will be subject to moderation before being displayed.