PHP单元测试-包含项目类的一次错误


PHP Unit test - include once error for project class

我创建了一些测试,但是运行它们有问题

In bootstrap I have:
    define("BASE_PATH",str_replace("''","/",dirname(__FILE__)));
//Get an array of your include paths
$include_parts = explode(PATH_SEPARATOR,get_include_path());
//Extend the paths
$include_parts[] = dirname(dirname(BASE_PATH)); //this is ../../
//recompile the paths and set them
set_include_path(implode(PATH_SEPARATOR,$include_parts));
/**
 * Test if phpunit running on php 5.3 or newer
 */
version_compare(PHP_VERSION, '5.3', '<') and exit('Test requires PHP 5.3 or newer.');
error_reporting(E_ALL & ~E_STRICT);
ini_set('display_errors', TRUE);
define('DOC_ROOT','');

当运行测试时,我得到警告

警告:include_once(): Failed open'/private/config/abc.php'以便包含(包含路径=/usr/地方/bin:/usr/地方/lib/php/::/opt/docroot/共享:/出口/home/约翰/public_html/运动")在约翰/出口/home//public_html/体育/私人/测试/足球/比赛/LineupTest.php第3行

怎么了,因为我看到了包含的路径,我看到了我的目录

您使用绝对路径包含abc.php,因此包含路径被忽略。您的文件系统中真的有/private/config/abc.php吗?

您包含'/private/config/abc.php'而不是'private/config/abc.php',因此这里的包含路径无关紧要。

有两个原因:

  • 是否你只是有一个打字错误(因此我的评论看到的行)
  • 或者你缺少一个定义,你的行读$path.'/private...,但$path是空的,因为某种原因,所以包含失败。