我正在使用Zend_Test。下面是我的tests / bootstrap.php文件:
// 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');
这是我的测试类中的setUp()方法(扩展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();
}
现在,在运行单元测试时,我得到以下特定代码行的错误:
$bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap');
$options = $bootstrap->getOptions();
致命错误:在非对象上调用成员函数getOptions()
有谁知道导致问题的原因以及如何解决问题?
感谢。
答案 0 :(得分:0)
看起来您的代码将单个参数视为对象。
来自http://framework.zend.com/manual/en/zend.controller.front.html
的文档getParam($name) allows you to retrieve a single parameter
at a time, using $name as the identifier.
答案 1 :(得分:0)
我修好了。结束在bootstrap中加载应用程序配置并将其存储在Zend_Registry中。这样容易多了。
$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV);
Zend_Registry::set('config', $config);