Skip to content

Instantly share code, notes, and snippets.

@luiscborbon
Created May 29, 2017 04:26
Show Gist options
  • Select an option

  • Save luiscborbon/cd9fe126ea0df1cd86dce29e54edd012 to your computer and use it in GitHub Desktop.

Select an option

Save luiscborbon/cd9fe126ea0df1cd86dce29e54edd012 to your computer and use it in GitHub Desktop.
Sample Phing build.yml
---
project:
_name: "Phing Build Tests"
_default: "phpunit"
_basedir: "."
# Global Properties
properties:
- _name: tests.dir
_value: "./tests"
- _name: tests.phpunit.dir
_value: "."
- _name: tests.reports.dir
_value: "${tests.phpunit.dir}/reports"
- _name: tests.codecoverage
_value: "false"
- _name: test.class
_value: "${test}"
# PHPUnit Targets
resolvepaths:
- _propertyName: tests.dir.resolved
_file: "${tests.phpunit.dir}"
- _propertyName: tests.reports.dir.resolved
_file: "${tests.phpunit.dir}/reports"
- _propertyName: tests.classes.dir.resolved
_file: "${tests.phpunit.dir}/classes"
- _propertyName: phing.classes.dir.resolved
_file: "../classes"
- _propertyName: phing.etc.dir.resolved
_file: "../etc"
paths:
- _id: incthis
pathelements:
- _dir: "${tests.dir.resolved}"
- _dir: "${tests.classes.dir.resolved}"
targets:
# Configure
- _name: configure
items:
- echo: "-------------------------------------------------"
- echo: " +++++ Running Phing unit tests"
- echo: "-------------------------------------------------"
# Cannot use __FILE__ because that is the AdhocTask not this build.xml file
- adhoc: "define('PHING_TEST_BASE', dirname($this->getProject()->getProperty('phing.file')));"
# startup will have changed the include_path, so set it back now
- includepath: _classpathRef="incthis"
- mkdir: _dir="${tests.reports.dir.resolved}/tests"
- mkdir: _dir="${tests.reports.dir.resolved}/coverage"
filesets:
- _id: relevant-tests
_dir: "${tests.classes.dir.resolved}"
include: _name="**/*${test.class}.php"
exclude: _name="**/Svn*TaskTest.php"
# Reports
- _name: reports
items:
- delete: dir="tmp"
- mkdir: dir="tmp"
- adhoc: " @include_once 'PHPUnit/Autoload.php'; "
- phpunit: _codecoverage="${tests.codecoverage}" _haltonerror="true" _haltonfailure="true" _printsummary="true" _pharlocation="/usr/local/bin/phpunit" _configuration="phpunit-sparse.xml" _bootstrap="../vendor/autoload.php"
formatters:
- _type: xml _usefile="true" _todir="${tests.reports.dir.resolved}" _outfile="test-results.xml"
- _type: clover _todir="${tests.reports.dir.resolved}"
- _type: plain _usefile="false"
batchtest:
filesets:
- refid: relevant-tests
- _phpunitreport: _format="frames" _todir="${tests.reports.dir.resolved}/tests" _infile="${tests.reports.dir.resolved}/test-results.xml" _styledir="${phing.etc.dir.resolved}"
coditions:
- if:
equals: _arg1="${tests.codecoverage}" _arg2="true"
then:
coverage-report:
_outfile: reports/coverage.xml"
reports:
- title: Phing _todir="reports/coverage" _styledir="${phing.etc.dir.resolved}" _usesorttable="true"
conditions:
- if:
equals: _arg1="${tests.codecoverage}" _arg2="true"
then:
coverage-setup:
_database: "reports/coverage.db"
filesets:
- _dir: "${phing.classes.dir.resolved}"
include: _name="**/*.php"
depends: [configure]
# Initialize
- _name: initialize
# items:
# run the insert-sql target of the build.xml unless we are doing this for one specific test
# - phing: _phingFile="build.xml" _target="insert-sql"
properties:
- _name: test.class
_value: ""
_override: true
_unless: test
# PHPUnit
- _name: phpunit
description: "Executes the PHPUnit test suite. To run a specific test: 'phing -Dtest=NameOfTest'"
depends: [initialize,reports]
---
project:
_basedir: "."
_default: phpunit
_name: "Phing Build Tests"
paths:
-
_id: incthis
pathelements:
-
_dir: "${tests.dir.resolved}"
-
_dir: "${tests.classes.dir.resolved}"
properties:
-
_name: tests.dir
_value: ./tests
-
_name: tests.phpunit.dir
_value: "."
-
_name: tests.reports.dir
_value: "${tests.phpunit.dir}/reports"
-
_name: tests.codecoverage
_value: false
-
_name: test.class
_value: "${test}"
resolvepaths:
-
_file: "${tests.phpunit.dir}"
_propertyName: tests.dir.resolved
-
_file: "${tests.phpunit.dir}/reports"
_propertyName: tests.reports.dir.resolved
-
_file: "${tests.phpunit.dir}/classes"
_propertyName: tests.classes.dir.resolved
-
_file: ../classes
_propertyName: phing.classes.dir.resolved
-
_file: ../etc
_propertyName: phing.etc.dir.resolved
targets:
-
_name: configure
filesets:
-
_dir: "${tests.classes.dir.resolved}"
_id: relevant-tests
exclude:
_name: "**/Svn*TaskTest.php"
include:
_name: "**/*${test.class}.php"
items:
-
echo: "-------------------------------------------------"
-
echo: " +++++ Running Phing unit tests"
-
echo: "-------------------------------------------------"
-
adhoc: "define('PHING_TEST_BASE', dirname($this->getProject()->getProperty('phing.file')));"
-
includepath:
_classpathRef: incthis
-
mkdir:
_dir: "${tests.reports.dir.resolved}/tests"
-
mkdir:
_dir: "${tests.reports.dir.resolved}/coverage"
-
_name: reports
conditions:
-
if:
equals:
_arg1: "${tests.codecoverage}"
_arg2: true
then:
coverage-setup:
_database: reports/coverage.db
filesets:
-
_dir: "${phing.classes.dir.resolved}"
include:
_name: "**/*.php"
depends:
- configure
items:
-
delete:
dir: tmp
-
mkdir:
dir: "tmp"
-
adhoc: " @include_once 'PHPUnit/Autoload.php'; "
-
batchtest:
filesets:
-
refid: relevant-tests
formatters:
-
_outfile: test-results.xml
_todir: "${tests.reports.dir.resolved}"
_type: xml
_usefile: true
-
_todir: "${tests.reports.dir.resolved}"
_type: clover
-
_type: plain
_usefile: false
phpunit:
_bootstrap: ../vendor/autoload.php
_codecoverage: "${tests.codecoverage}"
_configuration: phpunit-sparse.xml
_haltonerror: true
_haltonfailure: true
_pharlocation: /usr/local/bin/phpunit
_printsummary: true
-
_phpunitreport:
_format: frames
_infile: "${tests.reports.dir.resolved}/test-results.xml"
_styledir: "${phing.etc.dir.resolved}"
_todir: "${tests.reports.dir.resolved}/tests"
coditions:
-
if:
equals:
_arg1: "${tests.codecoverage}"
_arg2: true
then:
coverage-report:
_outfile: reports/coverage.xml"
reports:
-
_styledir: "${phing.etc.dir.resolved}"
_todir: reports/coverage
_usesorttable: true
title: Phing
-
_name: initialize
_unless: test
items:
-
phing:
_phingFile: build.xml
_target: insert-sql
properties:
-
_name: test.class
_override: true
_value: ""
-
_name: phpunit
depends:
- initialize
- reports
description: "Executes the PHPUnit test suite. To run a specific test: 'phing -Dtest=NameOfTest'"
---
project:
basedir: "."
default: phpunit
name: "Phing Build Tests"
paths:
-
name: incthis
pathelements:
-
dir: "${tests.dir.resolved}"
-
dir: "${tests.classes.dir.resolved}"
properties:
-
name: tests.dir
value: ./tests
-
name: tests.phpunit.dir
value: "."
-
name: tests.reports.dir
value: "${tests.phpunit.dir}/reports"
-
name: tests.codecoverage
value: false
-
name: test.class
value: "${test}"
resolvepaths:
-
file: "${tests.phpunit.dir}"
name: tests.dir.resolved
-
file: "${tests.phpunit.dir}/reports"
name: tests.reports.dir.resolved
-
file: "${tests.phpunit.dir}/classes"
name: tests.classes.dir.resolved
-
file: ../classes
name: phing.classes.dir.resolved
-
file: ../etc
name: phing.etc.dir.resolved
targets:
-
filesets:
-
dir: "${tests.classes.dir.resolved}"
exclude:
name: "**/Svn*TaskTest.php"
include:
name: "**/*${test.class}.php"
name: relevant-tests
items:
-
echo: "-------------------------------------------------"
-
echo: " +++++ Running Phing unit tests"
-
echo: "-------------------------------------------------"
-
adhoc: "define('PHING_TEST_BASE', dirname($this->getProject()->getProperty('phing.file')));"
-
includepath:
classpathRef: incthis
-
mkdir:
dir: "${tests.reports.dir.resolved}/tests"
-
mkdir:
dir: "${tests.reports.dir.resolved}/coverage"
name: configure
-
conditions:
-
if:
equals:
arg1: "${tests.codecoverage}"
arg2: true
then:
coverage-setup:
database: reports/coverage.db
filesets:
-
dir: "${phing.classes.dir.resolved}"
include:
name: "**/*.php"
depends:
- configure
items:
-
delete:
dir: tmp
-
mkdir:
dir: tmp
-
adhoc: " @include_once 'PHPUnit/Autoload.php'; "
-
batchtest:
filesets:
-
refid: relevant-tests
formatters:
-
outfile: test-results.xml
todir: "${tests.reports.dir.resolved}"
type: xml
usefile: true
-
todir: "${tests.reports.dir.resolved}"
type: clover
-
type: plain
usefile: false
phpunit:
bootstrap: ../vendor/autoload.php
codecoverage: "${tests.codecoverage}"
configuration: phpunit-sparse.xml
haltonerror: true
haltonfailure: true
pharlocation: /usr/local/bin/phpunit
printsummary: true
-
coditions:
-
if:
equals:
arg1: "${tests.codecoverage}"
arg2: true
then:
coverage-report:
outfile: reports/coverage.xml"
reports:
-
styledir: "${phing.etc.dir.resolved}"
title: Phing
todir: reports/coverage
usesorttable: true
phpunitreport:
format: frames
infile: "${tests.reports.dir.resolved}/test-results.xml"
styledir: "${phing.etc.dir.resolved}"
todir: "${tests.reports.dir.resolved}/tests"
name: reports
-
items:
-
phing:
file: build.xml
target: insert-sql
name: initialize
properties:
-
name: test.class
override: true
value: ""
unless: test
-
depends:
- initialize
- reports
description: "Executes the PHPUnit test suite. To run a specific test: 'phing -Dtest=NameOfTest'"
name: phpunit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment