2008年9月12日星期五

[fw-mvc] Singletons in ZF mvc components and testing

Hello everyone, I was wondering why there are so many singleton in the
main components of the mvc framework...
For example I was trying to work with the front controller for testing
purposes, but I have found out that the constructor is protected and I
have to deal with a singleton instance. Singleton are 'pathological
liars' in testing like Google bloggers said.
However, the instance of the front controller can be reset and the
Zend_Test components works well also with request, helpers and so on.
My components are not being reset anyway, as they are not engineered
like Zend ones. For instance, I have an Otk_Loader whose autoload
function resolve paths basing also on prefixes specified at bootstrap
(Otk_Model_* goes to application/models/ and so on). So when I run a
Zend_Test_PHPUnit_ControllerTestCase extension prefixes get loaded
multiple times (for every dispacth()).
In fact, statis classes preserve state along the application life, and
my test will be so happy if I can instance an Application class where
a front controller, router, request, controllers, ecc. resides and
where I put my objects. So to perform an integration test I only have
to instance an Application. This approach is forbidden because front
controller is singleton and I can't instance it by myself.
The point is I will transform my static class in normal objects, but
how can my controllers and tests access them? I should put my model
factory in an helper? Front controller parameters? Zend_Registry?

--
Giorgio Sironi
Piccolo Principe & Ossigeno Scripter
http://www.sourceforge.net/projects/ossigeno

没有评论: