programing

pHPUnit에서 clover.xml을 생성할 때 상대 경로를 정의하시겠습니까?

megabox 2023. 10. 26. 20:56
반응형

pHPUnit에서 clover.xml을 생성할 때 상대 경로를 정의하시겠습니까?

PHPUnit로 WordPress 플러그인에 통합 테스트를 실행하고 있으며 커버리지를 생성할 때clover.xml파일, 에 있는 파일 이름 속성clover.xml내 파일에 대한 절대적인 경로를 가질 것입니다. 예를 들어.

<file name="/Users/denis/vagrant-local/www/project/public_html/wp-content/plguins/my-plugin/file-that-is-tested.php">

이 파일을 SonarQuebe로 보내야 하기 때문에 SonarQuebe로 보낼 때마다 이 파일을 수정하여 상대 경로만 가질 수 있도록 해야 합니다(시작).wp-config폴더)

<file name="wp-content/plguins/my-plugin/file-that-is-tested.php">

첫 번째 버전을 보내면 SonarQube가 코드 커버리지를 0.0%로 보고하고 나머지 버전을 보내면 일부 커버리지가 표시됩니다(PHPU nit에서 생성하는 것과 다르지만 중요하지 않습니다).

PHPUnit 구성에서 이 파일 이름 속성을 지정할 수 있는 방법이 있습니까? 아니면 테스트를 실행할 때마다 bash 스크립트를 실행하여 이 추가 부분을 삭제해야 합니까?

편집

phpunit.xml.dist다음과 같습니다.

<?xml version="1.0" encoding="UTF-8"?>
<phpunit
  backupGlobals="false"
  backupStaticAttributes="false"
  beStrictAboutCoversAnnotation="true"
  bootstrap="tests/bootstrap.php"
  colors="true"
  convertErrorsToExceptions="true"
  convertNoticesToExceptions="true"
  convertWarningsToExceptions="true"
  printerClass="Codedungeon\PHPUnitPrettyResultPrinter\Printer"
  stopOnError="false"
  stopOnFailure="false"
  stopOnIncomplete="false"
  stopOnSkipped="false"
  verbose="true"
  >
  <testsuites>
    <testsuite name="integration">
      <directory prefix="test-" suffix=".php">./tests/integration/</directory>
    </testsuite>
  </testsuites>
  <filter>
    <whitelist>
      <directory>./</directory>
      <exclude>
        <directory>./node_modules</directory>
        <directory>./vendor</directory>
        <directory>./tests</directory>
        <directory suffix=".php">./src/old</directory>
      </exclude>
    </whitelist>
  </filter>
  <logging>
    <log type="coverage-html" target="tests/_reports/coverage" lowUpperBound="35" highLowerBound="80" />
    <log type="coverage-clover" target="tests/_reports/clover.xml"/>
    <log type="coverage-php" target="tests/_reports/logs/coverage.cov"/>
    <log type="junit" target="tests/_reports/logs/logfile.xml"/>
  </logging>
</phpunit>

기본적으로 절대 경로의 일부를 검색하고 제거하는 Symfony 명령을 만들었습니다.

https://github.com/dingo-d/woo-solo-api/tree/develop/bin

그러면 작곡가 대본에 이렇게 쓸 수 있습니다.

    "scripts": {
        "test:coverage": [
            "@php ./vendor/bin/codecept run Integration --coverage --coverage-xml --coverage-html --ansi",
            "@php bin/console clean-coverage /Users/denis.zoljom/Sites/personal/plugins-testing/ --ansi"
        ]
    },

아니면 어떤 스위트룸을 사용하던지.두번째 명령은 경로의 절대적인 부분을 제거합니다.coverage.serialized그리고.coverage.xml서류철

언급URL : https://stackoverflow.com/questions/58765505/define-the-relative-path-when-clover-xml-is-generated-in-phpunit

반응형