PHPUnit不允许我包含文件 [英] PHPUnit doesn't allow me to include files
问题描述
每当我尝试包含文件时,PHPUnit都会给我一条错误消息.例如,下面的代码给了我错误:
PHPUnit is giving me an error message whenever I try to include a file. For example the follwing code gives me the error:
<?php
include_once "PHPUnit/Autoload.php";
require_once "controller/ProductController.php";
class SecurityTests extends PHPUnit_Framework_TestCase
{
public function testSmth() {
$this->assertTrue(1==1);
}
}
?>
但是,如果我删除第四行(require_once "controller/ProductController.php";
),它将运行正常.
But if I remove the fourth line (require_once "controller/ProductController.php";
), it runs fine.
我得到的错误是:
Warning: require_once(PHPUnit/Framework/Error.php): failed to open stream: No such file or directory in E:\wamp\bin\php\php5.4.3\pear\PHPUnit\Util\ErrorHandler.php on line 48
我在php.ini文件中的include_path是:
My include_path in the php.ini file is:
include_path = ".;E:\wamp\bin\php\php5.4.3\pear\;E:\wamp\www\renting\"
奇怪的是:
<?php
echo get_include_path(); **// Will echo .;E:\wamp\bin\php\php5.4.3\pear\;E:\wamp\www\renting\**
require_once 'PHPUnit/Autoload.php';
require_once 'controller/AccountController.php';
echo get_include_path(); **// Will echo E:/wamp/www/renting/**
还有:
<?php
require_once 'controller/AccountController.php';
echo get_include_path(); **// Will echo E:/wamp/www/renting/**
require_once 'PHPUnit/Autoload.php';
echo get_include_path(); **// Will not even echo.**
这对我来说很奇怪.
有什么想法吗?
推荐答案
好,我花了几天的时间才弄清楚这一点.我希望没人能经历我所经历的一切.
Ok, it took me days to figure this one out. I hope nobody will ever go through what I went.
我在php.ini中:
I had in my php.ini:
include_path = ".;E:\wamp\bin\php\php5.4.3\pear\;E:\wamp\www\renting\"
但是因为我以前在我的ini文件中不使用多个php include路径,所以我使用了
But because I used to not use multiple php include paths in my ini file, I had used
set_include_path("E:/wamp/www/renting/");
在某些文件中,即使它们不是我要包含的文件.
in some of the files, even if they weren't the ones that I was trying to include.
无论如何,这听起来可能很愚蠢和令人困惑,但是如果您发现自己由于某种原因而无法正确加载PHPUnit,请考虑您的代码是否可能以某种方式更改了include路径.
Anyway, it might sound silly and confusing, but if you find yourself in a situation where PHPUnit does not load properly for some reason, think of the possibility of your code changing the include path somehow.
这篇关于PHPUnit不允许我包含文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!