配置特定於 LoVullo Associates 程式設計標準的 QA 和開發工具。該軟體包與lovullo/phpqatools
結合,旨在成為新 PHP 專案的基礎。
只需在專案的composer.json
中需要它
"require-dev" : {
"lovullo/phpqaconfig" : " @stable "
}
或者
$ composer require --dev lovullo/phpqaconfig
在專案根目錄中建立一個包含以下內容的build.xml
檔案:
xml version = " 1.0 " encoding = " utf-8 " ?>
< project name = " project-name " >
< import file = " ${basedir}/vendor/lovullo/phpqaconfig/build.xml " />
project >
在專案根目錄中建立一個phpunit.xml
文件,其中包含以下內容:
xml version = " 1.0 " encoding = " UTF-8 " ?>
< phpunit verbose = " true " >
< testsuites >
< testsuite name = " ProjectName " >
< directory suffix = " Test.php " >tests/ directory >
testsuite >
testsuites >
< logging >
< log type = " coverage-html " target = " build/coverage " />
< log type = " coverage-clover " target = " build/logs/clover.xml " />
< log type = " coverage-crap4j " target = " build/logs/crap4j.xml " />
< log type = " junit " target = " build/logs/junit.xml " logIncompleteSkipped = " false " />
logging >
phpunit >
如果您在其他地方已有 PHPUnit 配置,請參閱下方的「自訂」部分。
開發時,請使用以下 ant 目標:
例如:
$ ant phpcs phpmd phpcpd
配置持續整合(即 Jenkins)時, composer
必須下載並安裝此儲存庫,然後才能執行ant
任務。使用以下命令為 Jenkins 新增“執行 Shell”建置步驟:
$ composer install -o
接下來,新增具有以下目標的“Invoke Ant”建置步驟:
build-qa
這將運行check_mergeconflicts
、 phplint
、 phpunit
、 phpcs-ci
、 pdepend
、 phpmd-ci
、 phpcpd-ci
、 phploc-ci
和phpdox
。
對於需要快速運行且只需要最少數量的 QA 檢查的作業,請改為執行以下目標:
build-quick
這將運行check_mergeconflicts
、 phplint
和phpunit
。
根據您的特定專案的情況,將其他建置目標新增到您的build.xml
檔案中。
包含的build.xml
假定所有 QA 工具都安裝到./vendor/bin
。如果它們安裝在其他地方,請為其位置提供一個toolsdir
屬性:
xml version = " 1.0 " encoding = " utf-8 " ?>
< project name = " project-name " >
< property name = " toolsdir " value = " ${basedir}/bin/ " />
< import file = " ${basedir}/vendor/lovullo/phpqaconfig/build.xml " />
project >
預設情況下,包含的build.xml
會對專案中的所有 PHP 檔案執行php -l
,專案根目錄中的vendor/
目錄除外。您可以使用phplintignore
屬性覆寫此設定:
xml version = " 1.0 " encoding = " utf-8 " ?>
< project name = " project-name " >
< property name = " phplintignore " value = " components/**/*,vendor/**/* " />
< import file = " ${basedir}/vendor/lovullo/phpqaconfig/build.xml " />
project >
預設情況下,包含的build.xml
假定在與其自身相同的目錄中有一個phpunit.xml
檔。如果您已經有位於其他位置的phpunit.xml
文件,您可以如下覆寫配置:
xml version = " 1.0 " encoding = " utf-8 " ?>
< project name = " project-name " >
< property name = " phpunitconfig " value = " ${basedir}/app/ " />
< import file = " ${basedir}/vendor/lovullo/phpqaconfig/build.xml " />
project >
您可以透過指定phpcsignore
屬性來自訂在phpcs
檢查中忽略的檔案:
xml version = " 1.0 " encoding = " utf-8 " ?>
< project name = " project-name " >
< property name = " phpcsignore " value = " app/,bin/,vendor/,web/ " />
< import file = " ${basedir}/vendor/lovullo/phpqaconfig/build.xml " />
project >
預設情況下,只有vendor
目錄被排除在檢查之外。
您可以透過覆寫phpcsstandard
屬性來變更 PHP_CodeSniffer 標準使用的內容:
xml version = " 1.0 " encoding = " utf-8 " ?>
< project name = " project-name " >
< property name = " phpcsstandard " value = " PSR1,PSR2 " />
< import file = " ${basedir}/vendor/lovullo/phpqaconfig/build.xml " />
project >
您可以透過指定phpmdignore
屬性來自訂在phpmd
檢查中忽略的檔案:
xml version = " 1.0 " encoding = " utf-8 " ?>
< project name = " project-name " >
< property name = " phpmdignore " value = " app,bin,vendor,web " />
< import file = " ${basedir}/vendor/lovullo/phpqaconfig/build.xml " />
project >
預設情況下,只有vendor
目錄被排除在檢查之外。
您可以透過指定phpcpdignore
屬性來自訂在phpcpd
檢查中忽略的檔案:
xml version = " 1.0 " encoding = " utf-8 " ?>
< project name = " project-name " >
< property name = " phpcpdignore " value = " --exclude vendor --exclude app " />
< import file = " ${basedir}/vendor/lovullo/phpqaconfig/build.xml " />
project >
預設情況下,只有vendor
目錄被排除在檢查之外。
xml version = " 1.0 " encoding = " utf-8 " ?>
< phpdox xmlns = " http://xml.phpdox.net/config " silent = " true " >
< bootstrap />
< project name = " phpdox " source = " ${basedir}/src " workdir = " ${basedir}/build/phpdox/xml " >
< collector publiconly = " false " backend = " parser " >
< include mask = " *.php " />
< inheritance resolve = " true " />
collector >
< generator output = " ${basedir}/build/docs " >
< enrich base = " ${basedir}/build " >
< source type = " build " />
< source type = " phploc " >
< file name = " logs/phploc.xml " />
source >
< source type = " git " >
< git binary = " git " />
< history enabled = " true " limit = " 15 " cache = " ${phpDox.project.workdir}/gitlog.xml " />
source >
< source type = " checkstyle " >
< file name = " logs/checkstyle.xml " />
source >
< source type = " phpunit " >
< file name = " logs/phpunit " />
source >
< source type = " pmd " >
< file name = " logs/pmd.xml " />
source >
enrich >
< build engine = " html " enabled = " true " output = " html " >
< template dir = " ${phpDox.home}/templates/html " />
< file extension = " html " />
build >
generator >
project >
phpdox >
如果您不希望為專案執行某些 QA 工具,請在包含基礎build.xml
檔案之前新增下列一項或多項disable
屬性:
xml version = " 1.0 " encoding = " utf-8 " ?>
< project name = " project-name " >
< property name = " disable-phpunit " value = " true " />
< property name = " disable-pdepend " value = " true " />
< property name = " disable-phpmd " value = " true " />
< property name = " disable-phpcs " value = " true " />
< property name = " disable-phpcpd " value = " true " />
< import file = " ${basedir}/vendor/lovullo/phpqaconfig/build.xml " />
project >