我有这段代码:
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 功能
答案 0 :(得分:2)
在测试中使用https://github.com/mikey179/vfsStream。该库将允许您模拟大多数文件系统操作,包括file_get_contents()
。
答案 1 :(得分:0)
为什么不能创建包含模拟文件内容的变量?