/
[testing] Making In-Portal code easier to test

[testing] Making In-Portal code easier to test

Right now it's pretty hard to test In-Portal's code, because each class:

  1. gets reference to kApplication class by calling $this->Application = kApplication::Instance();

  2. then retrieves current database connection by calling $this->Conn = $this->Application->GetADODBConnection();

  3. then if that class needs another class, then it does $another_object = $this->Application->recallObject('some-alias-name');

With all of that in place it's pretty hard to mock anything to test any individual class in isolation. All is tied to kApplication class, because it implements Facade pattern and allows any other class to access any part of a system.

The first step would be to pass kApplication class instance directly to any class, that is being created. This way in tests we can create any mocked clone of kApplication class to fit out needs. This of course is going to end up with a Dependency Injection Container, but first we need to understand how we can do this in a way that won't result in a major backwards compatibility break.

 

P.S.

I will continue to add ideas to this disussion as long as I have them.

More reading: http://blog.astrumfutura.com/2011/10/zend-framework-2-0-dependency-injection-part-2/

Related Discussions