phpunit测试类没有错误,而类在那里吗? [英] phpunit test class not found error while class is there?
本文介绍了phpunit测试类没有错误,而类在那里吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的目录结构
application
---modules
------admin
---------models
-----------User.php
这是我的用户模型类
class admin_Model_User
{
//User.php
}
这是我的UserTest类,具有简单的AssertType
This is my UserTest Class with simple AssertType
class admin_Model_UserTest
extends PHPUnit_Framework_TestCase
{
public function testUserModel()
{
$testUser = new admin_Model_User();
$this->assertType("admin_Model_User",$testUser);
}
}
运行此命令时.我正在关注错误
When I run this. I am getting following Errors
[tests]# phpunit
PHPUnit 3.5.13 by Sebastian Bergmann.
0
Fatal error: Class 'admin_Model_User' not found in /web/zendbase/tests/application/modules/admin/models/UserTest.php on line 18
我知道必须有一些路径设置.我真的无法弄清楚到底是什么错.寻找帮助.....
I know there my must be some path setting. I really could not able to figure out what is really wrong. Looking for help.....
推荐答案
我要做的就是这个
//file:ControllerTestCase.php
<?php
require_once GLOBAL_LIBRARY_PATH. '/Zend/Application.php';
require_once GLOBAL_LIBRARY_PATH. '/Zend/Test/PHPUnit/ControllerTestCase.php';
abstract class ControllerTestCase extends Zend_Test_PHPUnit_ControllerTestCase
{
protected $_application;
protected function setUp()
{
$this->bootstrap = array($this, 'appBootstrap');
parent::setUp();
}
public function appBootstrap()
{
$this->_application = new Zend_Application(APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$this->_application->bootstrap();
/**
* Fix for ZF-8193
* http://framework.zend.com/issues/browse/ZF-8193
* Zend_Controller_Action->getInvokeArg('bootstrap') doesn't work
* under the unit testing environment.
*/
$front = Zend_Controller_Front::getInstance();
if($front->getParam('bootstrap') === null) {
$front->setParam('bootstrap', $this->_application->getBootstrap());
}
}
}
//,然后在Bootstrap文件中require_once. 多数民众赞成在:)它正在工作.
// and then require_once it in Bootstrap file. thats all :) it is working.
这篇关于phpunit测试类没有错误,而类在那里吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文