Skip to content

Code Coverage XML report generate empty files #692

@aviator-ua

Description

@aviator-ua
Q A
php-code-coverage version 7.0.7
PHP version 7.3.6
Driver Xdebug
Xdebug version (if used) 2.7.2
Installation Method Composer
Usage Method PHPUnit
PHPUnit version (if used) 8.3.4

Target Class

<?php
declare(strict_types=1);

namespace App\Service;

class SoapClientService
{
    /**
     * @const string
     */
    const URL = 'http://example.com/service.jws?wsdl';

    /**
     * @var \SoapClient
     */
    protected $soapClient = null;

    /**
     * @param string $url
     * @return \SoapClient
     * @throws \InvalidArgumentException
     */
    public function getSoapClient(string $url = null)
    {
        if (!isset($this->soapClient)) {
            try {
                $this->soapClient = new \SoapClient(
                    $url ?? self::URL
                );
            } catch (\Throwable $error) {
                throw new \InvalidArgumentException('Failed to initialize Soap Client');
            }
        }

        return $this->soapClient;
    }
}

Target TestCase

<?php
declare(strict_types=1);

namespace App\Tests\Service;

use App\Service\SoapClientService;
use PHPUnit\Framework\TestCase;

/**
 * Unit test for SoapClientService
 */
class SoapClientServiceTest extends TestCase
{

    public function testGetSoapClient(): void
    {
        $client = new SoapClientService();

        $this->expectException(\InvalidArgumentException::class);
        $client->getSoapClient('no-wsdl');
    }
}

Command for generate Code Coverage XML Report

vendor/bin/phpunit -v --coverage-xml build/coverage-xml

After executing comand, folder build/coverage-xml contains empty files.

Other reports (HTML, Clover, PHP) works as expected.

Also reproduced on the previous version of sebastianbergmann/php-code-coverage.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions