douan6815 2017-07-13 09:20
浏览 92
已采纳

预提交钩子,用于检查Symfony的PHP代码覆盖率和代码嗅探器

How can I do a pre-commit hook for PHP Symfony code to analyze code coverage and code sniffer report? What are commands and tools I should use?

As of now, I can generate a code coverage report using PHPUnit in clover format:

#!/bin/bash

echo "##################################################################################################"
echo "Starting PHPUnit tests : "`date "+%y-%m-%d %H-%M-%S"`
echo "##################################################################################################"

php app/console -e=dev doctrine:database:drop --force
php app/console -e=dev doctrine:database:create
php app/console -e=dev doctrine:schema:create
php app/console -e=dev -n doctrine:fixtures:load
#phpunit -c app --coverage-html build/html
phpunit -c app --log-junit build/unit.xml
'[' -f build/coverage.xml ']'
phpunit -c app --coverage-clover build/coverage.xml
php app/console -e=dev doctrine:schema:drop --force
php app/console -e=dev doctrine:database:drop --force
echo "Finishing Cron at "`date "+%y-%m-%d %H-%M-%S"`
echo "Cron Task Complete"
echo "##################################################################################################"
  • 写回答

2条回答 默认 最新

  • douyuben9434 2017-07-13 09:26
    关注

    If your bash script works as expected, you just need to name it pre-commit and put it in your git hooks: /path/to/repo/.git/hooks. You'll find some sample in this directory.

    For more information about git hooks: https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks

    Then, for you code sniffer, I recommend https://github.com/squizlabs/PHP_CodeSniffer.

    There is also https://github.com/phpro/grumphp that will do everything for you.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?