I am working with Zend_Test. Below is my tests/bootstrap.php file:
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', 'testing');
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));
require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('Ca_');
Zend_Controller_Action_HelperBroker::addPrefix('Ca_Controller_Action_Helper');
$resourceLoader = new Zend_Loader_Autoloader_Resource(array(
'namespace' => "Social",
'basePath' => APPLICATION_PATH . "/../library",
));
$resourceLoader->addResourceType('facebook', 'Facebook/', 'Facebook');
This is my setUp() method in my test class (which is extending Zend_Test_PHPUnit_DatabaseTestCase):
public function setUp()
{
$this->bootstrap = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
$this->entityUser = new Ca_Model_Entity_User_Registered();
$a = $this->getAdapter();
$a->setFetchMode(Zend_Db::FETCH_OBJ);
$a->query("SET FOREIGN_KEY_CHECKS=0;");
parent::setUp();
}
Now, when running a unit test I get the following error for this particular line of code:
$bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap');
$options = $bootstrap->getOptions();
Fatal error: Call to a member function getOptions() on a non-object
Does anyone know what is causing the issue and how I can resolve it ?
Thanks.
I fixed it. Ended up loading the application config in bootstrap and storing it in Zend_Registry. Much easier that way.
$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV);
Zend_Registry::set('config', $config);