2017-02-10 13 views
1

& 보호 방법을 PhpUnit의 코드 커버리지 보고서에서 숨길 수 있습니까? 코드 커버리지 보고서에서 비공개 + 보호 된 메소드를 숨기시겠습니까?

나는 다른 사람들이 하나가 "간접적"을 테스트해야하지만 난 정말가 전화를받을 경우 치료 여부를 내가 나를 위해 @covers을 설정하는 것이 시간의 완전한 낭비라고 생각하지 않는다 것을 건의 알고 개인 유틸리티 방법.

은 여기 내 phpunit.xml 당신은 볼 필요가있는 경우 :

<phpunit 
     backupGlobals="false" 
     backupStaticAttributes="false" 
     bootstrap="vendor/autoload.php" 
     colors="true" 
     convertErrorsToExceptions="true" 
     convertNoticesToExceptions="true" 
     convertWarningsToExceptions="true" 
     processIsolation="false" 
     stopOnFailure="false" 
     syntaxCheck="false" 
     timeoutForSmallTests="1" 
     timeoutForMediumTests="10" 
     timeoutForLargeTests="60"> 

    <testsuites> 
     <testsuite name="default"> 
      <directory>./tests</directory> 
      <exclude> 
       <directory suffix=".php">./src/Internal</directory> 
      </exclude> 
     </testsuite> 
    </testsuites> 

    <filter> 
     <whitelist> 
      <directory suffix=".php">./src</directory> 
     </whitelist> 
    </filter> 

    <logging> 
     <log type="coverage-html" target="./log/codeCoverage" charset="UTF-8" yui="true" highlight="true" lowUpperBound="50" highLowerBound="80"/> 
     <log type="testdox-html" target="./log/testdox.html"/> 
    </logging> 
</phpunit> 

code coverage

+2

음, 공용 메서드가 개인 메서드를 사용하는 경우 왜 제외 할 것입니까? 이것은 나에게 전혀 의미가 없습니다. :) – DonCallisto

+0

@DonCallisto IMO 노력만큼 가치가 없습니다. 감소하는 수익. 단위 테스트는 출력이 정확한지 확인합니다. 코드 커버리지는 모든 다른 시나리오에 적용되는지 테스트합니다. 필자가 사설 유틸리티 메소드의 일부를 지나치게 일반화했다 할지라도, 필자는 실제로 lib 디렉토리의 모든 코드 행을 실행해야만 하는가? 나는 그렇게 생각하지 않는다. – mpen

+0

음,이 경우에는 코드 커버리지를 끄십시오. 그렇지 않으면 public 메소드 imho에만 적용하는 것이 이해가되지 않습니다. – DonCallisto

답변

2

글쎄, 내가 아는 한, 그것은 phpunit을 기능이 아니다 당신은 php-code-coverage 프로젝트를 포크와 소스 코드를 편집해야합니다 . 아마 그것은 당신이 찾고있는 대답이 아니지만 이것이 지금 유일한 선택 인 것 같습니다.

변경 사항은 매우 간단합니다. 당신은

if (get_class($token) == 'PHP_Token_FUNCTION') { 
    $methodVisibility = $token->getVisibility(); 

    if ($methodVisibility == 'private' || $methodVisibility == 'protected') { 
     $endLine = $token->getEndLine(); 

     for ($i = $token->getLine(); $i <= $endLine; $i++) { 
      self::$ignoredLines[$filename][$i] = TRUE; 
     } 
    } 
} 

enter image description here 방법 getSomething@codeCoverageIgnore 또는 기타 문서 블록을 사용하지 않고 무시됩니다 추가 조건을 CodeCoverage::getLinesToBeIgnoredmethod을 편집하고 추가 할 수 있습니다.