PHPUnit 5.7:模拟file_get_contents

时间:2018-02-09 15:55:38

标签: php phpunit

我有这段代码:

if (is_null($contenu)) {
    if (file_exists($filePath)) {
        $contenu = file_get_contents($filePath);
    } else {
        throw new \Oft\Mvc\Exception\NotFoundException('Fichier inexisant');
    }
}

我想模仿 file_get_contents 功能

2 个答案:

答案 0 :(得分:2)

在测试中使用https://github.com/mikey179/vfsStream。该库将允许您模拟大多数文件系统操作,包括file_get_contents()

答案 1 :(得分:0)

为什么不能创建包含模拟文件内容的变量?