在phpunit中使用opendir()时出现问题
在phpUnit中测试类时,会抛出以下错误:在phpunit中使用opendir()时出现问题,php,phpunit,opendir,Php,Phpunit,Opendir,在phpUnit中测试类时,会抛出以下错误: 1) TableTest::testGetTableInputForm opendir(./views/img/tables): failed to open dir: No such file or directory 该文件是可访问的,并且该类正在生产环境中工作 如果我直接在testclass内部调用opendir,它将抛出相同的错误。如果我将绝对路径提供给opendir,phpunit中的测试将冻结 此行为还显示以root用户身份运行测试 甚
1) TableTest::testGetTableInputForm
opendir(./views/img/tables): failed to open dir: No such file or directory
该文件是可访问的,并且该类正在生产环境中工作
如果我直接在testclass内部调用opendir,它将抛出相同的错误。如果我将绝对路径提供给opendir,phpunit中的测试将冻结
此行为还显示以root用户身份运行测试
甚至可以用phpunit测试opendir吗
phpunit配置:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/3.7/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
beStrictAboutTestsThatDoNotTestAnything="false"
beStrictAboutOutputDuringTests="false"
checkForUnintentionallyCoveredCode="false"
bootstrap="/external_data/jenkins/jenkins-home/jobs/admin/workspace/test/bootstrap.php"
cacheTokens="false"
colors="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
forceCoversAnnotation="false"
mapTestClassNameToCoveredClassName="false"
printerClass="PHPUnit_TextUI_ResultPrinter"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
testSuiteLoaderFile="phpunit/src/Runner/StandardTestSuiteLoader.php"
timeoutForSmallTests="1"
timeoutForMediumTests="10"
timeoutForLargeTests="60"
strict="true"
verbose="true"
当前文件夹是运行phpunit的文件夹,除非在测试中调用了chdir。。。也许相对路径不是你想的那样?我会做一个var_dumprealpath。;查看脚本认为当前路径是什么…var_dumprealpath。;在项目的测试目录中按预期返回。但这不重要,因为我也尝试了绝对路径?是的,这部分令人费解:/。。。作为替代方案,您是否考虑过模拟文件系统?我经常在我的测试中使用,也许这会有帮助….?谢谢,我会研究一下-你曾经在phpunit中成功地使用过本机文件测试吗?是的,从来没有遇到过问题真的。。。有几次,当我没有使用vfstream时,我有一个包含测试资产的文件夹,我将它作为参数传递给我正在测试的类,它通常是有效的…虽然我不太使用opendir,但我倾向于使用scandir,但这不会有什么不同。。。。