问题描述
现在,我正在测试的实际文件位于 root->foo->config
接下来,如果我选择要测试的文件,然后右键单击,new PHPtest,我会看到以下屏幕:
所以到目前为止一切正常。一切都是自动预先输入的。
所以我的 ip_require.PHP 进入 root->tests->foo
<?PHP
namespace config;
use foo\ip_request;
use PHPUnit\Framework\TestCase;
class ip_requestTest extends TestCase
{
public function testGetRealIpAddr()
{
$local = new ip_request();
$this->assertEquals('127.0.0.1',$local->getRealIpAddr());
}
}
<?xml version="1.0" encoding="UTF-8"?>
<target name="test">
<PHPunit
bootstrap="tests/bootstrap.PHP"
colors="true"
> <!-- changed from vendor/autoload.PHP-->
<testsuites>
<testsuite name = "Website">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<PHP>
<ini name="error_reporting" value="-1" />
<env name="KERNEL_CLASS" value="App\Kernel" />
<env name="APP_ENV" value="test" />
<env name="APP_DEBUG" value="1" />
<env name="SHELL_VERBOSITY" value="-1" />
</PHP>
</PHPunit>
</target>
ini_set('display_errors',true);
error_reporting(E_ALL);
include $_SERVER['DOCUMENT_ROOT'].'\foo\ip_requestTest.PHP';
我悬停在类上的所有内容看起来都指向正确的方向。
如果我点击并关注测试文件中的课程,它会将我带到正确的位置
我的 PHPUnit 安装到最新版本,在命令行和 composer.json 中验证
"require": {
"PHPunit/PHPunit": "9.3","ext-MysqLi": "*"
},
有什么想法吗?我已经没有链接可以尝试了...
解决方法
我找到了一个修复程序,至少可以通过 bootstrap.php 页面。
include __DIR__ . '/../foo/config/ip_request.php';
然后我的终端中仍然有类似的错误消息,但最终让我的测试工作的是我确保 composer.json 具有相同版本的 PHPUnit。
一旦它们相同,它就起作用了!