【发布时间】:2010-11-06 07:24:01
【问题描述】:
这是一个非常具体的问题,我在谷歌上搜索了很多潜在的解决方案,但没有任何东西可以为我指明正确的方向。我写了一个 Zend_Controller_Action_Helper 来帮助我处理我的应用程序中的一些表单。现在在应用程序中它工作正常,但它似乎打破了我的测试。如果我注释掉将帮助程序添加到代理中的行,一切都会正常工作,但这会破坏对象。我得到的错误是
Fatal error: Class 'PHPUnit_Framework_Error_Notice' not found in /Users/chris/NetBeansProjects/myProject/library/ProcessForm.php on line 25
我不明白的是为什么它会在第 25 行抛出这个错误
public function processForm($aParam)
所以我想我应该粘贴一些代码来向您展示一些应用程序。我正在我的应用程序的引导程序中添加这个助手,就像这样..
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initHelpers()
{
// If I comment out these lines it all works
require_once 'ProcessForm.php';
Zend_Controller_Action_HelperBroker::addHelper(
new ProcessForm()
);
}
}
我的 PHPUnit 引导文件如下所示
require_once 'Zend/Application.php';
require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';
abstract class ControllerTestCase extends Zend_Test_PHPUnit_ControllerTestCase
{
protected $application;
public function setUp()
{
$this->bootstrap = array($this, 'appBootstrap');
parent::setUp();
$this->getFrontController()->setParam('bootstrap', $this->application->getBootstrap());
}
public function appBootstrap()
{
$this->application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
$this->application->bootstrap();
}
}
实际的助手看起来像这样
class ProcessForm extends Zend_Controller_Action_Helper_Abstract
{
/**
* @var Zend_Loader_PluginLoader
*/
public $pluginLoader;
/**
* Constructor: initialize plugin loader
*
* @return void
*/
public function __construct()
{
$this->pluginLoader = new Zend_Loader_PluginLoader();
}
public function processForm($aParam)
{
}
public function direct($aParam)
{
return $this->processForm($aParam);
}
}
【问题讨论】:
-
2 建议:由于它似乎找不到
PHPUnit_Framework_Error_Notice,您是否检查了该文件是否存在? ( Zend/Test/PHPUnit/Framework/Error/Notice.php) 并且错误似乎来自 ProcessForm 构造函数。所以,也许在另一个班级$this->pluginLoader = new Zend_Loader_PluginLoader(); -
它在您建议的路径中不存在,但它是路径中 PHPUnit 的一部分
标签: php zend-framework phpunit