【发布时间】:2019-07-27 15:09:18
【问题描述】:
this question 有同样的问题。但是,当我将 'DIR' 添加为 this answer 时,它却出现了错误。
我的目录结构:
app\业务逻辑层\searchController.php
app\数据访问层\connect.php
app\tests\test.php
test.php
<?php
namespace Tests;
require __DIR__.'/Business Logic Layer/searchController.php';
use PHPUnit\Framework\TestCase;
use Search\SearchController as DB;
class SearchTest extends TestCase
{
public function testsearch()
{
$Ctrl=new DB;
$result=$Ctrl->select();
$this->assertNotNull($result);
}
}
当我运行 phpunit 时,控制台显示错误
PHP 警告:require(F:\xamp\htdocs\AppRoot\app\tests/Business Logic Layer/searchController.php):无法打开流:F:\xamp\htdocs\AppRoot\ 中没有这样的文件或目录phonebook\tests\test.php 在第 3 行
但我的文件是 F:\xamp\htdocs\AppRoot\app\Business Logic Layer/searchController.php
我不知道怎么解决,请帮忙!
【问题讨论】:
-
只需将 print 替换为 require ,您就可以看到它是如何解释的。
-
错误显示 /tests/ 是您似乎正在运行它的地方。您正在运行什么命令以及在哪个文件夹中运行它。尝试下一个目录并运行它。