简体   繁体   中英

PHP Unit test - include once error for project class

I created some test but there is problem with running them

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','');

When running test I get warning

Warning: include_once(): Failed opening '/private/config/abc.php' for inclusion (include_path='/usr/local/bin:/usr/local/lib/php/:.:/opt/docroot/shared:/export/home/john/public_html/sports') in /export/home/john/public_html/sports/private/tests/Football/Match/LineupTest.php on line 3

What is wrong because I see that included path I see my dir.

You are including abc.php using an absolute path so the include path is ignored. Do you really have /private/config/abc.php in your filesystem?

You are including '/private/config/abc.php' and not 'private/config/abc.php' so the include path here doesn't matter.

That can have two causes:

  • Ether you just have a typo there (hence my comment to see the line)
  • or you are missing a define and your line reads $path.'/private... but $path is empty for some reason so the include is failing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM