Testing File dependencies and mocking
Posted: Sat Mar 31, 2007 8:32 pm
Using simpletest,
I'm trying to test a part of my application layer over the zend framework, which essentially checks to make sure the view or model classes exist before we initialize the object. I'm using class_exists in combination with autoload to acheive this.
So $component may equal "Application_View_Index" or "Application_Model_Index", etc. It is my understanding mocks need a base class to generate the mock. Considering the views and models are found in the application, and arn't even required to exist, how do I mock a class that doesn't exist? Do I just create a bare class Application_View_Index and mock it just for the sake of testing?
I'm trying to test a part of my application layer over the zend framework, which essentially checks to make sure the view or model classes exist before we initialize the object. I'm using class_exists in combination with autoload to acheive this.
Code: Select all
protected function _factoryComponent($name, $type)
{
$component = 'Application_'. $type .'_'. ucfirst($name);
if (!class_exists($component)) {
throw new Northern_Component_Exception('Cannot find "'. $component .'" component');
}
return new $component();
}