无法从工作单元测试用例构建最简单的套件

Bri*_*man 5 php tdd unit-testing simpletest

我已经开始对我的PHP程序使用单元测试,并认为Simpletest是一个很好的潜水地点.我将Simpletest文件添加到我的测试服务器,并在我的自定义PDO类上运行以下测试:

<?php
require_once('../simpletest/autorun.php');
require_once('../includes/inc_sql.php');

class TestOfSQL extends UnitTestCase{
    function testRead(){
        ...
    }

    function testWriteAndDelete(){
        ...
    }
}
?>
Run Code Online (Sandbox Code Playgroud)

这一切都很糟糕.我尝试构建一个涉及(到目前为止)测试文件的测试套件,如下所示:

<?php
require_once('../simpletest/autorun.php');

class AllTests extends TestSuite {

    function __construct(){
        parent::__construct();
        $this->addFile('inc_sql_test.php');
    }
}
Run Code Online (Sandbox Code Playgroud)

这会崩溃并烧伤,我得到以下读数:

Warning: include_once(inc_sql_test.php) [function.include-once]: failed to open stream: No such file or directory in E:\xampp\htdocs\historicMuncie\simpletest\test_case.php on line 382

Warning: include_once() [function.include]: Failed opening 'inc_sql_test.php' for inclusion (include_path='.;E:\xampp\php\PEAR') in E:\xampp\htdocs\historicMuncie\simpletest\test_case.php on line 382

Warning: file_get_contents(inc_sql_test.php) [function.file-get-contents]: failed to open stream: No such file or directory in E:\xampp\htdocs\historicMuncie\simpletest\test_case.php on line 418
all_tests.php
Fail: AllTests -> inc_sql_test.php -> Bad TestSuite [inc_sql_test.php] with error [No runnable test cases in [inc_sql_test.php]]
0/0 test cases complete: 0 passes, 1 fails and 0 exceptions.
Run Code Online (Sandbox Code Playgroud)

我已经玩过包含路径,Web根目录与服务器根表示法 - 想到的任何事情,但没有任何东西允许该测试套件正常运行.有任何想法吗?

Jus*_*ᚄᚒᚔ 2

当我看到 PHP 脚本中的相对路径时,我总是感到畏缩。使用基于公共根的“半绝对”路径时,实现和维护要容易得多。尝试:

$this->addFile( $_SERVER['DOCUMENT_ROOT'] . '/inc_sql_test.php' );
Run Code Online (Sandbox Code Playgroud)