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>
那麼,如果一個公共方法依賴於私有方法,爲什麼要排除它們呢?這對我來說沒有意義,真的:) – DonCallisto
@DonCallisto只是不值得IMO的努力。收益遞減。單元測試確保輸出是正確的,代碼覆蓋率確保我測試了所有不同的場景。我真的需要確保我執行我的庫中的每一行代碼,即使我可能過度泛化了一些私有實用工具方法嗎?我不這麼認爲。 – mpen
那麼,在這種情況下,只需關閉代碼覆蓋率,否則將它僅應用於公共方法imho是沒有意義的。 – DonCallisto