Well, one size doesn't fit all

I came across a curious bug today when after deploying a revision of one of web apps I've been working on. The automatic test suite had run its course, no errors. However, when I repeated one of the processes covered by a test manually, I ended up with a fatal error.

The reason the test worked fine while the real process didn't is a not entirely unimportant weakness in the test framework. The individual requests simulated by functional tests are not isolated from one another like regular requests would be. They all happen inside the same request context, so there is no teardown at the end and no cleanup. There are certain things in PHP that you can't undo unless you finish a request. One of those things is registering functions.

So what happened was that I included a helper (collection of functions) only in the template of the first request in the process. That was no problem in the test run because the functions stayed defined throughout, whereas in the real world, they wouldn't.

I'm trying to figure out what would be the best way to address this problem. The most thorough way, isolating every request into its own CLI session, would be impractical. Although it would address more than this very specific problem. The less general but easier to implement way would be to write a parser that checks whether every function used in the templates is defined or included in the template it's used in.

Leave a comment

Your comment