Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mocking up Apache session data for unit testing

I'm working with a web application that, normally, runs in mod_perl under Apache. A co-worker and I are trying to do some unit testing. Are there any good tools or techniques out there for mocking-up sessions and requests and the like that could help us exercise this code outside of the web server context?

like image 487
BlairHippo Avatar asked Oct 05 '11 19:10

BlairHippo


1 Answers

If you're using mod_perl 1, there is Apache::FakeRequest which comes with mod_perl. It is not a complete mock of the request object, so you have to add some methods of your own. Even more if your code uses Apache::Request. Yet more for cookies and uploads. Mostly you're going to be spending a lot of time with Test::MockObject. Fortunately, the Apache object interfaces are pretty straight forward.

If at all possible, you should consider switching to a Plack based framework (Catalyst, Dancer, etc...) which provide far more robust testing and debugging facilities. If you're using mod_perl2, you're in luck! It's easy (relative to mod_perl 1) to wrap a mod_perl2 application with Plack. Plack::App::FakeApache does most of the work for you. Here is a discussion sketching out the various techniques and benefits.

like image 70
Schwern Avatar answered Oct 10 '22 00:10

Schwern