PHPUnit错误“无法打开流:没有这样的文件或目录”

时间:2019-03-06 02:58:16

标签: php phpunit phpunit-testing

我对this question有相同的问题。但是当我将' DIR '添加为this answer时,却无法正常工作。

我的目录结构:

app \ Business Logic Layer \ 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 \中没有此类文件或目录第3行上的phonebook \ tests \ test.php

但是我的文件是F:\ xamp \ htdocs \ AppRoot \ app \ Business Logic Layer / searchController.php

我不知道如何解决它,请帮忙!

2 个答案:

答案 0 :(得分:0)

更改require __DIR__.'/Business Logic Layer/searchController.php';
require __DIR__.'\Business Logic Layer\searchController.php';

答案 1 :(得分:0)

我正在改变require __DIR__.'/Business Logic Layer/searchController.php';
require __DIR__.'/../Business Logic Layer/searchController.php';

它正在为我工​​作,谢谢大家的帮助!