I upgraded Xdebug version from 2.9.3 to 3.0.1 and I found some differences in code coverage results after run unit tests with --code-coverage.
Let's say, there are two environments:
- Environment 1: PHP 7.3.16, Xdebug 2.9.3, php-code-coverage 8.0.2, PHPUnit 9.0.2
- Environment 2: PHP 7.3.25, Xdebug 3.0.1, php-code-coverage 8.0.2, PHPUnit 9.0.2
Code example 1:
public function getAllOptions(): array
{
$this->_options = [
[
'label' => _'label 1,
'value' => 'value 1'
],
[
'label' => _'label 2,
'value' => 'value 2'
]
];
return $this->_options;
}
Results for Code example 1:
- Environment 1: 100% code coverage
- Environment 2: second line ($this->_options =) is marked as uncovered
Code example 2:
private function moveImportedFileToArchive(Operation $operation): void
{
$sourceFilePath = $this->_filesystem->getDirectoryWrite(DirectoryList::ROOT)->getAbsolutePath()
. $operation->getFileInfo()['file_path']
. '/'
. $operation->getFileInfo()['file_name'];
// @codingStandardsIgnoreStart
$fileName = basename($sourceFilePath);
// @codingStandardsIgnoreEnd
$archiveFileName = (int)gmdate('U') . '_' . $fileName;
$archivePath = static::ARCHIVE_DIR . $archiveFileName;
$this->_varDirectory->renameFile($sourceFilePath, $archivePath);
}
Results for Code example 2:
- Environment 1: 100% code coverage
- Environment 2: fourth line (. '/') is marked as uncovered
I do not have any idea, what can caused these differences.
They usually occurs in place, where value is assigned to variable (very often it is related to assigning array to variable or assigning variable to array or array to array)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…