我有执行此测试时运行特定测试的问题。当我一起运行所有测试时,此测试失败。从NetBeans内部或从命令行运行具有相同的结果。phpunit:单一测试运行时通过,当所有测试运行时都失败
与我的套件中的其他测试相比,这个测试是独一无二的,它从一个资源文件夹获取一个文件,然后将其复制到一个测试文件夹中(该文件夹在测试开始时创建并销毁最后)。
我认为这是一个相对/绝对路径的问题,但是当我转储源文件夹和目标文件夹时它们是相同的。
这是有问题的代码(失败的复制语句):
public function testRemoveRequirementFileValid()
{
$dbName = 'TRHUtilTest';
$reqID = 1;
$userID = 14;
$trhVersionID = 3;
//create the database
DBCreator::CreateProjectDatabaseAndTables($dbName);
DB::setConnectionInfo($dbName);
$fileName = 'example.png';
$sourceFolder = dirname(__FILE__).'\TRHUtilResources\\';
$targetLink = '../'.FolderDefine::GetFolder('TRH_RequirementLink', $dbName).$trhVersionID.'/'.$reqID.'/';
FileUtil::MKDirs($targetLink);
$targetFolder = FolderDefine::GetFolder('TRH_RequirementFile', $dbName).$trhVersionID.'\\'.$reqID.'\\';
//2 debugging statements
print PHP_EOL.'Source Folder: '.$sourceFolder.PHP_EOL;
print PHP_EOL.'Target Folder: '.$targetFolder.PHP_EOL;
copy($sourceFolder.$fileName, $targetFolder.$fileName);
$file = new File();
$file->setName($fileName);
$file->setLocation($targetLink);
$file->save();
$fileID = $file->getID();
//create the link between a requirement and a file
TRHUtil::RequirementFileLink($reqID, $fileID, $userID);
//assert that there is one record, then check the structure and then the contents
$this->assertEquals(1, DB::getRecordCount($dbName.'.files_reqs'));
$this->assertEquals(1, TRHUtil::RequirementFileLinkPresent($reqID, $dbName));
$this->assertEquals(1, TRHUtil::RequirementFileLinkCheck($reqID, $fileID, $dbName));
$this->assertEquals(1, count(TRHUtil::GetRequirementFileLinkID($reqID, $dbName)));
TRHUtil::RemoveRequirementFile($reqID, $dbName, $trhVersionID);
//assert that the records about this file are removed and that the folder where the file was staying is also removed
$this->assertEquals(0, DB::getRecordCount($dbName.'.files_reqs'));
$this->assertEquals(0, TRHUtil::RequirementFileLinkPresent($reqID, $dbName));
$this->assertEquals(0, TRHUtil::RequirementFileLinkCheck($reqID, $fileID, $dbName));
$this->assertEquals(0, TRHUtil::GetRequirementFileLinkID($reqID, $dbName));
$this->assertEquals(0, is_dir($targetFolder));
//remove the project folder
$projectFolder = FolderDefine::GetFolder('ProjectRoot', $dbName);
FileUtil::RRMDir($projectFolder);
}
调试语句然后再给:
Source Folder: D:\Inetpub\wwwroot\DTS\tests\util\TRHUtilResources\
Target Folder: D:\Inetpub\wwwroot\DTSfiles\TRHUtilTest\trh\reqs\3\1\
在NetBeans中的输出窗口,我也看到以下内容: copy(D:\Inetpub\wwwroot\DTSfiles\TRHUtilTest\trh\reqs\3\1\example.png): failed to open stream: No such file or directory
但是这个文件夹是以前创建的。值得注意的是,关于复制语句的错误仅显示第二个参数,并且此参数周围没有引号。
你需要显示你有问题的测试,以及它如何失败,以获得帮助。这听起来像是测试污染(测试会影响全局状态,导致以后的测试失败,或者从假设状态开始,而不是在执行“测试”之前确保测试场景与预期一致)。 – AD7six
究竟是什么意思呢? –
@ AD7six我添加了有问题的代码 – Tornado