简体   繁体   English

zend_test / phpunit的引导问题

[英]Bootstrapping issues with zend_test/phpunit

I am working with Zend_Test. 我正在使用Zend_Test。 Below is my tests/bootstrap.php file: 以下是我的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');

This is my setUp() method in my test class (which is extending Zend_Test_PHPUnit_DatabaseTestCase): 这是我的测试类中的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();        
}

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 致命错误:在非对象上调用成员函数getOptions()

Does anyone know what is causing the issue and how I can resolve it ? 有人知道导致问题的原因以及如何解决吗?

Thanks. 谢谢。

It looks like your code is treating a single parameter as an object. 看起来您的代码将单个参数视为对象。

From the docs at: http://framework.zend.com/manual/en/zend.controller.front.html 来自位于以下位置的文档: http : //framework.zend.com/manual/zh/zend.controller.front.html

getParam($name) allows you to retrieve a single parameter 
at a time, using $name as the identifier.

I fixed it. 我修好了它。 Ended up loading the application config in bootstrap and storing it in Zend_Registry. 最终将应用程序配置加载到引导程序中,并将其存储在Zend_Registry中。 Much easier that way. 这样容易得多。

$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV);
Zend_Registry::set('config', $config);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM