Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
153 views
in Technique[技术] by (71.8m points)

php - Xdebug 2 vs Xdebug 3 - differences in code coverage

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It is possible that some lines are no longer covered with Xdebug 3 due to it being much more selective on which information is gathered.

I believe your first issue is fixed in Xdebug 3.0.2 (#1922). For the second issue, if it still persists after upgrading to Xdebug 3.0.2, please file a bug report at https://bugs.xdebug.org following the instructions at https://xdebug.org/reporting-bugs — for Code Coverage bugs I would generally only need a fully parsable PHP file that exhibits the problem. StackOverflow is not the place for reporting bugs.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...