这个让我难住。我一直在使用PHPUnit几个月,所以我不是那么绿......但我期待着指出我正在犯的明显错误的方向!如果我从浏览器运行“app”,下面概述的初始化过程工作正常 - 但PHPUnit正在窒息......任何人都可以让我摆脱我的痛苦吗?PHPUnit包含路径问题
我试图测试一个自制的MVC,为研究目的。它遵循典型的ZF布局。 这里的索引页:
include './../library/SKL/Application.php';
$SKL_Application = new SKL_Application();
$SKL_Application->initialise('./../application/configs/config.ini');
这里的应用程序类(初期...)
include 'bootstrap.php';
class SKL_Application {
/**
* initialises the application
*/
public function initialise($file) {
$this->processBootstrap();
//purely to test PHPUnit is working as expected
return true;
}
/**
* iterates over bootstrap class and executes
* all methods prefixed with "_init"
*/
private function processBootstrap() {
$Bootstrap = new Bootstrap();
$bootstrap_methods = get_class_methods($Bootstrap);
foreach ($bootstrap_methods as $method) {
if(substr($method,0,5) == '_init'){
$bootstrap->$method();
}
}
return true;
}
}
这里的测试:
require_once dirname(__FILE__).'/../../../public/bootstrap.php';
require_once dirname(__FILE__).'/../../../library/SKL/Application.php';
class SKL_ApplicationTest extends PHPUnit_Framework_TestCase {
protected $object;
protected function setUp() {
$this->object = new SKL_Application();
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown() {
}
public function testInitialise() {
$this->assertType('boolean',$this->object->initialise());
}
}
,但我一直在第一障碍绊倒!
PHP Warning: include(bootstrap.php): failed to open stream:
No such file or directory in path\to\files\SKL\Application.php on line 9
有什么想法?
我想通了 - 我必须将所需的文件位置追加到包含路径。应用程序本身只是从相对路径中提取文件,但这在PHPUnit中不起作用 - 所以我只是将它们设置在单独的文件中并将文件包含在测试中。 – sunwukung 2010-08-24 09:52:34