Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get PHPUnit coverage #1

Open
tuanpt-0634 opened this issue Jul 8, 2022 · 2 comments
Open

How to get PHPUnit coverage #1

tuanpt-0634 opened this issue Jul 8, 2022 · 2 comments

Comments

@tuanpt-0634
Copy link
Contributor

Coverage driver

Để generate coverage report bằng PHPUnit, cần có coverage driver:
image

Có 3 drivers bao gồm (ưu tiên từ trên xuống dưới):

  • pcov cho PHPUnit version >= 8
    php -dextension=pcov.so -dpcov.enabled=1 -dpcov.directory=src ./vendor/bin/phpunit --coverage-text

    NOTE: pcov.directory=src, trong đó src là thư mục chứa source code

  • phpdbg
    phpdbg -qrr ./vendor/bin/phpunit --coverage-text
  • XDebug
    XDEBUG_MODE=coverage php -dzend_extension=xdebug.so ./vendor/bin/phpunit --coverage-text

NOTE: chạy trong docker container đã cài sẵn các extension pcov, xdebug

Coverage format

Có nhiều loại format cho coverage:

Code Coverage Options:
  --coverage-clover <file>    Generate code coverage report in Clover XML format
  --coverage-crap4j <file>    Generate code coverage report in Crap4J XML format
  --coverage-html <dir>       Generate code coverage report in HTML format
  --coverage-php <file>       Export PHP_CodeCoverage object to file
  --coverage-text=<file>      Generate code coverage report in text format [default: standard output]
  --coverage-xml <dir>        Generate code coverage report in PHPUnit XML format

Nhưng thông dụng nhất là --coverage-text thường dùng trong CI hoặc xem nhanh kết quả và --coverage-html để xem chi tiết dưới dạng web dashboard và --coverage-clover dùng cho Sun*CI

@tuanpt-0634
Copy link
Contributor Author

PHPUnit Coverage text example
image

@tuanpt-0634
Copy link
Contributor Author

PHPUnit Coverage html example

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant