Generating code coverage report in Clover XML format … PHP Fatal error: Cannot declare class …, because the name is already in use in

I want to get coverage.xml for CodeCov. PHP 8.0.2 PHPUnit 9.5.2 Xdebug 3.0.2

My class. It's very simple, just practice for code coverage src/Car.php

<?php
/**
* This class is for car.
*/

class Car
{
 public function GetColor()
 {
   return 'Blue';
 }
}

Test file. tests/CarTest.php

<?php
include_once __DIR__ .'/../src/Car.php';
use PHPUnit\Framework\TestCase;
/**
 * @coversDefaultClass Car
 */
class CarTest extends TestCase
{
  /**
  * @covers Car::GetColor
  */
  public function testCarGoodColor(): void
  {
    $car = new Car();
    $this->assertSame('Blue', $car->GetColor());
  }
}

When I enter

./vendor/bin/phpunit tests/ --coverage-clover ./coverage.xml

I get this message:

PHPUnit 9.5.2 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.0.2 with Xdebug 3.0.2
Configuration: /Applications/CI-CD/phpunit.xml

.                                                                   1 / 1 (100%)

Time: 00:00.187, Memory: 8.00 MB

OK (1 test, 1 assertion)

Generating code coverage report in Clover XML format ... PHP Fatal error:  Cannot declare 
class Car, because the name is already in use in /Applications/CI-CD/src/Car.php on line 8

Fatal error: Cannot declare class Car, because the name is already in use in /Applications/CI-CD/src/Car.php on line 8

How to resolve this issue with classes?



Read more here: https://stackoverflow.com/questions/66264221/generating-code-coverage-report-in-clover-xml-format-php-fatal-error-cannot

Content Attribution

This content was originally published by Artur Konevnikov at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: