Hello everyone!

We have been investing plenty of personal time and energy for many years to share our knowledge with you all. However, we now need your help to keep this blog running. All you have to do is just click one of the adverts on the site, otherwise it will sadly be taken down due to hosting etc. costs. Thank you.

You can use this example as you build.xml or modify it as you wish. It does the most of the stuff as you might need. If not then add missing part.


Composer.json


You can probably add phpunit and code_sniffer to it.


"require-dev": {
"doctrine/doctrine-fixtures-bundle": "2.2.0",
"doctrine/data-fixtures": "1.1.1",
"phpspec/phpspec": "2.2.1",
"behat/behat": "2.5.5",
"behat/mink-extension": "1.3.3",
"behat/mink": "1.5.0",
"behat/symfony2-extension": "1.1.2",
"behat/mink-selenium2-driver": "1.1.1",
"behat/mink-browserkit-driver": "1.1.0",
"behat/mink-goutte-driver": "1.0.9",
"guzzle/guzzle": "3.9.2",
"guzzlehttp/guzzle": "5.0.2",
"phing/phing": "2.11.0",
"fabpot/php-cs-fixer": "1.9",
"sebastian/phpcpd": "2.0.2",
"phpmd/phpmd": "2.2.3",
"pdepend/pdepend": "2.0.0",
"phploc/phploc": "2.1.3",
"phpdocumentor/phpdocumentor": "2.8.3"
},

Build folder structure


build
phing
behat
.gitkeep
phpcpd
.gitkeep
phpdoc
.gitkeep
phploc
.gitkeep
phpmd
.gitkeep

Build.xml


I suggest you to set passthru="false" for each targets and see how the output changes. If you get writing permission error on cache or log folders then you can include two additional lines below to main build.xml file.


<exec logoutput="true" checkreturn="true" passthru="true" command="chmod -Rf 775 app/cache" dir="./" />
<exec logoutput="true" checkreturn="true" passthru="true" command="chmod -Rf 775 app/logs" dir="./" />

If you cannot solve security vulnerabilities, then you can change checkreturn="true" to checkreturn="false" temporarily at the bottom.


<?xml version="1.0" encoding="UTF-8"?>

<project name="football" default="default" basedir=".">

<!-- GLOBAL VARIABLES -->
<property name="reports.folder" value="build/phing" />
<property name="source.folder" value="src" />
<!-- END -->

<!-- FILESET -->
<fileset id="sourcecode" dir="${project.basedir}/${source.folder}">
<include name="*.php" />
<include name="**/*.php" />
</fileset>
<!-- END -->

<!-- AVAILABLE COMMANDS -->
<target name="default"
description="Running full test suite ..."
depends="
build.reports.clear,
cache.clear, cache.warm,
composer.update, composer.install,
doctrine.update.entities, doctrine.update.schema, doctrine.data.fixtures,
test.phpcsfixer, test.phpcpd, test.phpmd, test.phploc, test.phpspec, test.behat,
project.documentation, project.security
" />
<!-- END -->

<!-- CLEAR BUILD LOGS -->
<target name="build.reports.clear">
<echo msg="Clearing build reports ..." />
<exec logoutput="true" checkreturn="true" command="rm -Rf ${reports.folder}/behat/*" dir="./" />
<exec logoutput="true" checkreturn="true" command="rm -Rf ${reports.folder}/phpcpd/*" dir="./" />
<exec logoutput="true" checkreturn="true" command="rm -rf ${reports.folder}/phpdoc/*" dir="./" />
<exec logoutput="true" checkreturn="true" command="rm -rf ${reports.folder}/phpdoc/.htaccess" dir="./" />
<exec logoutput="true" checkreturn="true" command="rm -rf ${reports.folder}/phploc/*" dir="./" />
<exec logoutput="true" checkreturn="true" command="rm -rf ${reports.folder}/phpmd/*" dir="./" />
</target>
<!-- END -->

<!-- CLEAR CACHE AND LOGS -->
<target name="cache.clear">
<echo msg="Clearing application cache and logs ..." />
<exec logoutput="true" checkreturn="true" passthru="true" command="rm -Rf app/cache/test/*" dir="./" />
<exec logoutput="true" checkreturn="true" passthru="true" command="rm -Rf app/logs/test/*" dir="./" />
</target>
<!-- END -->

<!-- WARM CACHE -->
<target name="cache.warm">
<echo msg="Warming up cache ..." />
<exec logoutput="true" checkreturn="true" passthru="true" command="php app/console cache:clear --env=test"
dir="./" />
<exec logoutput="true" checkreturn="true" passthru="true" command="php app/console cache:warm --env=test"
dir="./" />
</target>
<!-- END -->

<!-- COMPOSER SELF UPDATE -->
<target name="composer.update">
<echo msg="Running composer self-update ..." />
<exec logoutput="true" checkreturn="true" passthru="true" command="composer self-update" dir="./" />
</target>
<!-- END -->

<!-- COMPOSER INSTALL -->
<target name="composer.install">
<echo msg="Running composer install ..." />
<exec logoutput="true" checkreturn="true" passthru="true" command="composer install" dir="./" />
</target>
<!-- END -->

<!-- DOCTRINE UPDATE ENTITIES -->
<target name="doctrine.update.entities">
<echo msg="Updating doctrine entities ..." />
<exec logoutput="true" checkreturn="true" passthru="true"
command="php app/console doctrine:generate:entities ApplicationBackendBundle --no-backup --env=test"
dir="./" />
<exec logoutput="true" checkreturn="true" passthru="true"
command="php app/console doctrine:generate:entities ApplicationFrontendBundle --no-backup --env=test"
dir="./" />
</target>
<!-- END -->

<!-- DOCTRINE UPDATE SCHEMA -->
<target name="doctrine.update.schema">
<echo msg="Updating doctrine schema ..." />
<exec logoutput="true" checkreturn="true" passthru="true"
command="php app/console doctrine:schema:update --force --no-interaction --no-debug --env=test"
dir="./" />
</target>
<!-- END -->

<!-- DOCTRINE DATA FIXTURES -->
<target name="doctrine.data.fixtures">
<echo msg="Loading doctrine data fixtures ..." />
<exec logoutput="true" checkreturn="true" passthru="true"
command="php app/console doctrine:fixtures:load --no-interaction --no-debug --env=test"
dir="./" />
</target>
<!-- END -->

<!-- PHP-CS-FIXER -->
<target name="test.phpcsfixer">
<echo msg="Checking coding standards ..." />
<exec logoutput="true" checkreturn="true" passthru="true"
command="bin/php-cs-fixer fix ${source.folder} --dry-run --diff --verbose
--fixers=-yoda_conditions,-phpdoc_align,short_array_syntax"
dir="./" />
</target>
<!-- END -->

<!-- PHPCPD -->
<target name="test.phpcpd">
<echo msg="Checking similar code blocks ..." />
<tstamp />
<phpcpd>
<fileset refid="sourcecode" />
<formatter type="pmd" outfile="${reports.folder}/phpcpd/${DSTAMP}-${TSTAMP}.xml" />
</phpcpd>
</target>
<!-- END -->

<!-- PHPMD -->
<target name="test.phpmd">
<echo msg="Checking potential problems in code ..." />
<tstamp />
<phpmd rulesets="codesize,unusedcode">
<fileset refid="sourcecode" />
<formatter type="xml" outfile="${reports.folder}/phpmd/${DSTAMP}-${TSTAMP}.xml" />
</phpmd>
</target>
<!-- END -->

<!-- PHPLOC -->
<target name="test.phploc">
<echo msg="Measuring project size ..." />
<tstamp />
<exec logoutput="false" checkreturn="true" passthru="false"
command="bin/phploc --count-tests
--log-csv ${reports.folder}/phploc/${DSTAMP}-${TSTAMP}.csv
--log-xml ${reports.folder}/phploc/${DSTAMP}-${TSTAMP}.xml
${source.folder}" dir="./" />
</target>
<!-- END -->

<!-- PHPSPEC -->
<target name="test.phpspec">
<echo msg="Running phpspec tests ..." />
<exec logoutput="true" checkreturn="true" passthru="true"
command="bin/phpspec run --no-ansi --format=dot"
dir="./" />
</target>
<!-- END -->

<!-- BEHAT -->
<target name="test.behat">
<echo msg="Running backend behat tests ..." />
<tstamp />
<exec logoutput="true" checkreturn="true" passthru="true"
command="bin/behat --profile=backend -f progress,html
--out ,${reports.folder}/behat/b_${DSTAMP}-${TSTAMP}.html"
dir="./" />
<echo msg="Running frontend behat tests ..." />
<exec logoutput="true" checkreturn="true" passthru="true"
command="bin/behat --profile=frontend -f progress,html
--out ,${reports.folder}/behat/f_${DSTAMP}-${TSTAMP}.html"
dir="./" />
</target>
<!-- END -->

<!-- PHPDOCUMENTOR -->
<target name="project.documentation">
<echo msg="Creating documentation ..." />
<exec logoutput="false" checkreturn="true" passthru="false"
command="bin/phpdoc -d ${source.folder} -t ${reports.folder}/phpdoc --template clean --title=${phing.project.name}"
dir="./" />
</target>
<!-- END -->

<!-- PROJECT SECURITY CHECK -->
<target name="project.security">
<echo msg="Checking security vulnerabilities ..." />
<exec logoutput="true" checkreturn="true" passthru="true" command="php app/console security:check"
dir="./" />
</target>
<!-- END -->

</project>