2011-05-03 8 views
2

내 상황에 어느 것이 더 적합할지 결정하려고합니다. phpunit docs (매우 제한적 임)에 따르면 허용 목록은 디렉토리 안에있는 모든 파일을 포함해야하지만 그렇게하지 않는 것 같습니다. 누구든지 제안을하거나 phpunit 설명서 이외의 좋은 참조 나를 가리킬 수 있습니다. XML 구성 파일을 사용하고 있습니다. 미리 감사드립니다!phpunit 화이트리스트 대 블랙리스트

<?xml version="1.0" encoding="utf-8"?> 
<phpunit> 
    <filter> 
    <whitelist> 
     <directory suffix=".php">/home/ddohr/git/project/</directory> 
    <exclude> 
     <directory suffix=".php">/home/ddohr/git/project/vendor/</directory> 
     <directory suffix=".php">/home/ddohr/git/project/plugins/</directory> 
     <directory suffix=".php">/home/ddohr/git/project/test/</directory> 
    </exclude> 
    </whitelist> 
    </filter> 
</phpunit> 
+0

그것은 나를 위해 그런 식으로 작동합니다 : [지금 사용하고 XML 파일 (https://github.com/ircmaxell/PHP-CryptLib/blob/master 그런 이유로 나는이 작은 보석을 추가 /test/phpunit.xml.dist) – ircmaxell

+0

허용 목록에있는 파일이나 디렉토리를 제외하면 어떤 파일에 "접근"해도 파일이 계속 들어올 것입니다. 자동으로 모든 파일을 가져 오지 않을까요? 내 화이트리스트 디렉토리에있는 파일들이 많아서 뽑아 내지 못하는 것 같습니다. – Dave

+0

@dave : PHPUnit 루트 태그는 어디에 있습니까? 검시 태그는 어 딨지? 질문을 편집하여 전체 XML 파일을 게시하십시오 ... – ircmaxell

답변

1

업데이트 : 더 이상 아무 위 phpunit을 3.6와 함께 작동 아래. 새 솔루션은 Add files to code-coverage white/blacklists in bootstrap.php for PHPUnit을 참조하십시오.

원래 대답들은 상호 배타적이며, 화이트리스트는 블랙리스트에 걸쳐 승리하는 '화이트리스트 블랙리스트 대 "질문 노트에 관해서는

. 우리는 테스트없이 클래스에보고 된 0 % 커버리지를 원하기 때문에 프로젝트에 화이트리스트를 사용합니다. 우리의 bootstrap.php 모듈은 화이트리스트를 설정했는데 그 당시에는 phpunit.xml에 두는 것보다 관리가 쉬워 보였습니다.

function includeDirectoryForCodeCoverage($path) { 
    PHP_CodeCoverage_Filter::getInstance() 
      ->addDirectoryToWhitelist($path); 
} 

function includeFileForCodeCoverage($path) { 
    PHP_CodeCoverage_Filter::getInstance() 
      ->addFileToWhitelist($path); 
} 

function includeFilesForCodeCoverage(array $paths) { 
    PHP_CodeCoverage_Filter::getInstance() 
      ->addFilesToWhitelist($paths); 
} 

블랙리스트 :이 PHP_CodeCoverage로 실제 호출을 추상화하는 간단한 도우미가

includeDirectoryForCodeCoverage(MY_LIBRARY_PATH); 

: 예를 들어

는 라이브러리 프로젝트의 bootstrap.php은 화이트리스트에 소스를 추가 할 includeDirectoryForCodeCoverage()를 사용 그러나 여전히 편리합니다. PHPUnit은 블랙리스트 파일의 코드에 대한 스택 추적 항목을 숨 깁니다.

function ignoreDirectoryInStackTraces($path) { 
    PHP_CodeCoverage_Filter::getInstance() 
      ->addDirectoryToBlacklist($path); 
} 
+0

PHPUnit 3.6에서'PHP_CodeCoverage_Filter :: getInstance'가 제거되었으며 XML 기반이 아닌 블랙리스트 설정은 엉망이되었습니다. – Tgr

+0

3.6.x 이상에서 작동하는 솔루션에 대해서는 [PHPUnit의 경우'bootstrap.php'에있는 코드 - 범위 화이트/블랙리스트에 파일 추가] (http://stackoverflow.com/q/8085674/285873)를 참조하십시오. –

관련 문제