phing
PHing Is Not GNU make; it's a PHP project build system or build tool based on Apache Ant. Please refer to the Phing site for the roadmap and issue tracking.
Phing
phing is not gnu make; it's a php project build system or build tool based on apache ant. you can do anything with it that you could do with a traditional build system like gnu make, and its use of simple xml build files and extensible php 'task' classes make it an easy-to-use and highly flexible build framework. features include running phpunit and simpletest unit tests (including test result and coverage reports), file transformations (e.g. token replacement, xslt transformation, smarty template transformations), file system operations, interactive build support, sql execution, cvs/svn operations, tools for creating pear packages, and much more.
I'm trying to setup phing to work with travis-ci, but I can't get it to run a setup script to get all the dependencies installed.
My .travis.yml file is:
language: php
php:
- 5.2
script: ./.travis-phing.sh
In travis, I get the error:
/home/travis/build.sh: line 105: ./.travis-phing.sh: Permission denied
What is causing that?
Source: (StackOverflow)
I am a lone developer most of my time, working on a number of big, mainly PHP-based projects. I want to professionalize and automate how changes to the code base are handled, and create a Continuous Integration process that makes the transition to work in a team possible without having to make fundamental changes.
What I am doing right now is, I have a local test environment for every project; I use SVN for each project; changes are tested locally, and then transferred to the on-line version, usually via FTP. API documentation is generated manually from the source code; Unit tests are something I am getting into slowly, and it's not yet part of my daily routine.
The "build cycle" I am envisioning would do the following:
A changeset gets checked into SVN after having been tested locally.
I start the build process. The SVN HEAD revision gets checked out, modified if necessary, and made ready for upload.
API Documentation gets generated automatically - if I haven't set it up in detail yet, using a default template, scanning the whole code base.
The new revision is deployed to the remote location via FTP (Including some directory renaming, chmodding, importing databases, and the likes.) This is something I already like phing for very much, but I'm open for alternatives of course.
Unit tests residing in a predefined location are run. I am informed about their failure or success using E-Mail, RSS or (preferably) HTML output that I can grab and put into a web page.
(optionally) a end-user "changelog" text file in a pre-defined location gets updated with a pre-defined part of the commit message ("It is now possible to filter for both "foo" and "bar" at the same time). This message is not necessarily identical with the SVN commit message, which probably contains much more internal information.
Stuff like code metrics, code style checking and so on are not my primary focus right now, but on the long run, they certainly will. Solutions that bring this out-of-the-box are very kindly looked upon.
I am looking for
Feedback and experiences from people who are or were in a similar situation, and have successfully implemented a solution for this
Especially, good step-by-step tutorials and walkthroughs on how to set this up
Solutions that provide as much automation as possible, for example by creating a skeleton API, test cases and so on for each new project.
and also
- Product recommendations. What I know so far is phing/ant for building, and phpUnderControl or Hudson for the reporting part. I like them all as far as I can see, but I have of course no detailed experience with them.
I am swamped with work, so I have a strong inclination towards simple solutions. On the other hand, if a feature is missing, I'll cry about it being too limited. :) Point-and-click solutions are welcome, too. I am also to commercial product recommendations that can work with PHP projects.
My setup
I am working on Windows locally (7, to be exact) and most client projects are run on a LAMP stack, often on shared hosting (= no remote SSH).
I am looking for solutions that I can run in my own environment. I am ready to set up a Linux VM for this, no problem. Hosted solutions are interesting for me only if they provide all of the aspects described, or are flexible enough to interact with the other parts of the process.
Bounty
I am accepting the answer that I feel will give me the most mileage. There is a lot of excellent input here, I wish I could accept more than one answer. Thanks everyone!
Source: (StackOverflow)
I'm doing PHP development and I'm thinking of using one of these. I have both PHP and Java installed on my machine. In theory I could use any of the two.
What are the compelling arguments to pick Phing over Ant?
Source: (StackOverflow)
I'm using Phing to do post build tasks in Hudson.
I want to generate changelog containing all commits since last successful Hudson build. But looks like neither Hudson nor Git plugin for Hudson does not provide %last_build_time%
variable.
This would be satisfying solution, (but how to get the time?):
git log --pretty="%s" --since="%last_build_time%"
The only way I see for now is extracting it from the job xml file, but I do not know if it is possible with Phing.
How do you generate your change logs?
Source: (StackOverflow)
I want to use both Phing and Composer for my applications. Phing as the build system and Composer to manage dependencies. But which way around should they be used?
Currently we're installing Phing globally on all servers. Phing is supposed to completely automate the build of our various projects. Just checkout a copy of the project, run Phing with the default target and you should be good to. This also implies that there should be a Phing target in there that calls on Composer to install all dependencies. So, Phing calling composer. But I have been unable to find anything about this setup. There's no ComposerTask or anything similar and googling around doesn't reveal anyone working that way.
But I do see a lot of it the other way around. People using Composer to install Phing as a project dependency.
So, what are the (dis)advantages of each method? Am I trying to do it from the wrong way?
Source: (StackOverflow)
Does anyone use Phing to deploy PHP applications, and if so how do you use it? We currently have a hand-written "setup" script that we run whenever we deploy a new instance of our project. We just checkout from SVN and run it. It sets some basic configuration variables, installs or reloads the database, and generates a v-host for the site instance.
I have often thought that maybe we should be using Phing. I haven't used ant much, so I don't have a real sense of what Phing is supposed to do other than script the copying of files from one place to another much as our setup script does. What are some more advanced uses that you can give examples of to help me understand why we would or would not want to integrate Phing into our process.
Source: (StackOverflow)
we use phing to build and test our project. I want to remove dependencies on PEAR as much as possible so I can run different versions of packages for different projects. I have created a composer.json file which install all the necessary packages
{
"require": {
"php": ">=5.3.3",
"zendframework/zendframework": "2.2.*",
"doctrine/doctrine-orm-module": "*",
"phpoption/phpoption": "*"
},
"require-dev": {
"phing/phing": "*",
"phpunit/phpunit": "*",
"pdepend/pdepend": "*",
"phpmd/phpmd": "*",
"phploc/phploc": "*",
"phpdocumentor/phpdocumentor": "*",
"squizlabs/php_codesniffer": "*",
"mayflower/php-codebrowser": "*",
"sebastian/phpcpd": "*",
"zendframework/zftool": "dev-master",
"zendframework/zend-form": "*",
"hounddog/doctrine-data-fixture-module": "*",
"pear/console_commandline": "dev-trunk",
"pear/log": "dev-master",
"pear/pear_exception": "dev-master"
},
"config": {
"bin-dir": "vendor/bin/"
}
}
And I have a phing build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="SolExactConnector" default="build">
<property name="basedir" value="." override="true"/>
<property name="source" value="${basedir}/module"/>
<fileset dir="${source}" id="sourceWithoutTests">
<include name="**/*.php"/>
<exclude name="*/test/"/>
<exclude name="*/Module.php"/>
<exclude name="*/config/module.config.php"/>
<exclude name="*/test/Bootstrap.php"/>
</fileset>
<fileset dir="${source}" id="sourceWithTests">
<include name="**/*.php"/>
<exclude name="*/Module.php"/>
<exclude name="*/config/module.config.php"/>
<exclude name="*/test/Bootstrap.php"/>
</fileset>
<fileset dir="${source}" id="tests">
<include name="*/test/**/*Test.php"/>
</fileset>
<target name="prepare" description="Clean up and create artifact directories">
<delete dir="${basedir}/build/api"/>
<delete dir="${basedir}/build/code-browser"/>
<delete dir="${basedir}/build/coverage"/>
<delete dir="${basedir}/build/logs"/>
<delete dir="${basedir}/build/pdepend"/>
<delete dir="${basedir}/build/docs"/>
<mkdir dir="${basedir}/build/api"/>
<mkdir dir="${basedir}/build/code-browser"/>
<mkdir dir="${basedir}/build/coverage"/>
<mkdir dir="${basedir}/build/logs"/>
<mkdir dir="${basedir}/build/pdepend"/>
<mkdir dir="${basedir}/build/docs"/>
</target>
<target name="phpunit" description="Run unit tests" depends="prepare">
<coverage-setup database="${basedir}/build/logs/coverage.db">
<fileset refid="sourceWithoutTests"/>
</coverage-setup>
<phpunit haltonfailure="true" haltonerror="true" printsummary="true" bootstrap="test/Bootstrap.php"
codecoverage="true">
<formatter todir="${basedir}/build/logs" type="clover" outfile="clover.xml"/>
<formatter todir="${basedir}/build/logs" type="xml" outfile="junit.xml"/>
<batchtest>
<fileset refid="tests"/>
</batchtest>
</phpunit>
</target>
<target name="lint" description="Perform syntax check of sourcecode files" depends="prepare">
<phplint haltonfailure="true" cachefile="${basedir}/build/logs/lint.cache">
<fileset refid="sourceWithTests"/>
</phplint>
</target>
<target name="pdepend" description="Generate jdepend.xml and software metrics charts using PHP_Depend"
depends="prepare">
<phpdepend file="${source}">
<logger type="jdepend-xml" outfile="${basedir}/build/logs/jdepend.xml"/>
<logger type="jdepend-chart" outfile="${basedir}/build/pdepend/dependencies.svg"/>
<logger type="overview-pyramid" outfile="${basedir}/build/pdepend/overview-pyramid.svg"/>
</phpdepend>
</target>
<target name="phpmd" description="Generate pmd.xml using PHPMD" depends="prepare">
<phpmd file="${source}">
<formatter type="xml" outfile="${basedir}/build/logs/pmd.xml"/>
</phpmd>
</target>
<target name="phpcpd" description="Generate pmd-cpd.xml using PHPCPD" depends="prepare">
<phpcpd>
<formatter type="pmd" outfile="${basedir}/build/logs/pmd-cpd.xml"/>
<fileset refid="sourceWithTests"/>
</phpcpd>
</target>
<target name="phploc" description="Generate phploc.xml" depends="prepare">
<phploc reportType="xml" reportName="phploc"
reportDirectory="${basedir}/build/logs">
<fileset refid="sourceWithTests"/>
</phploc>
</target>
<target name="phpcs" description="Generate checkstyle.xml using PHP_CodeSniffer" depends="prepare">
<phpcodesniffer
standard="PSR2"
showSniffs="true"
showWarnings="true">
<fileset refid="sourceWithTests"/>
<formatter type="default" usefile="false"/>
<formatter type="checkstyle" outfile="${basedir}/build/logs/checkstyle-codesniffer.xml"/>
</phpcodesniffer>
</target>
<target name="hphpa" description="HipHop's static analyzer" depends="prepare">
<exec executable="wget" checkreturn="true">
<arg line="https://phar.phpunit.de/hphpa.phar"/>
</exec>
<exec executable="php hphpa.phar" checkreturn="true">
<arg line="--checkstyle ${basedir}/build/logs/checkstyle-hphpa.xml"/>
<arg line="${source}"/>
</exec>
<delete file="hphpa.phar"/>
</target>
<target name="phpdoc2" description="Generate API documentation using phpDox" depends="prepare">
<phpdoc2 title="API Documentation"
destdir="${basedir}/build/docs"
template="responsive-twig">
<fileset refid="sourceWithTests"/>
</phpdoc2>
</target>
<target name="phpcb" description="Aggregate tool output with PHP_CodeBrowser" depends="prepare">
<exec executable="phpcb">
<arg line="--log ${basedir}/build/logs
--source ${source}
--output ${basedir}/build/code-browser"/>
</exec>
</target>
<target name="composer" description="Installing dependencies" depends="prepare">
<delete dir="${basedir}/vendor"/>
<composer command="install">
<arg value="--dev"/>
</composer>
</target>
<target name="doctrine" description="Building Database/Doctrine" depends="prepare">
<copy file="${basedir}/config/autoload/local.php.test" tofile="${basedir}/config/autoload/local.php"
haltonerror="true"/>
<delete dir="${basedir}/data/db/"/>
<mkdir dir="${basedir}/data/db/"/>
<chmod file="${basedir}/data/db/" mode="777"/>
<exec executable="${basedir}/vendor/bin/doctrine-module">
<arg value="orm:schema-tool:create"/>
</exec>
<delete dir="${basedir}/data/DoctrineORMModule/Proxy"/>
<mkdir dir="${basedir}/data/DoctrineORMModule/Proxy"/>
<exec executable="${basedir}/vendor/bin/doctrine-module">
<arg value="orm:generate-proxies"/>
</exec>
<exec executable="${basedir}/vendor/bin/doctrine-module">
<arg value="data-fixture:import"/>
</exec>
</target>
<target name="build"
depends="lint,pdepend,phpcs,phpcpd,phpmd,hphpa,phpdoc2,composer,doctrine,phpunit,phpcb"/>
</project>
Some targets (like phpunit, phpmd and phploc) run fine but others don't? E.g. when I run phpcpd I get this error:
Execution of target "phpcpd" failed for the following reason:
/home/munnik/Sites/SolExactConnector/trunk/build.xml:83:16:
/home/munnik/Sites/SolExactConnector/trunk/build.xml:83:16: PHPCPDTask
depends on PHPCPD being installed and on include_path.
BUILD FAILED
/home/munnik/Sites/SolExactConnector/trunk/build.xml:83:16:
/home/munnik/Sites/SolExactConnector/trunk/build.xml:83:16: PHPCPDTask
depends on PHPCPD being installed and on include_path. Total time:
0.1250 seconds
Do I need to add the composer autoload or something like that?
Source: (StackOverflow)
Does anyone know if its possible to use phing to copy an entire folder with files and sub folders (joomla core download) to another folder, but without the .svn folders.
I have downloaded joomla using SVN, and I want to export it to my joomla dev folder using phing, without the need to have to list every single file type. My plan is to use this to keep my dev updated from the trunk.
I know how to exclude
But cannot find anyway to include everything without listing every file, or trying to guess every file type, just in case I miss something!
Suggestions
Paul
Source: (StackOverflow)
How to check if property ${foo}
has been set?
Bonus question: how to escape $
sign in <echo>
so I could output ${foo}
string (not the foo
variable substitution)?
PS: tried to google and read documentation, but couldn't find the answers. It's likely I'm missing something
Source: (StackOverflow)
I have a PHP application that is written with Zend Framework. It uses Phing for a build system and PHPUnit for unit testing. All these parts have configuration settings. Zend uses application.xml
, Phing uses build.xml
and optionally some build.properties
, and PHPUnit uses phpunit.xml
.
But where do I store information that is required by all three components? Think of database configuration (passwords for example).
In my case, the application.xml
has various sections (dev, staging, production) all with a different database configurations. I have recently integrated an ORM in my application and now I want to unittest my models. So I have a fourth database (unittesting) which is used by PHPUnit.
PHPUnit can handle fixture data but not database schemas. So, I was thinking I'd write a Phing build target that copies the database schema from production or staging to the unittest database. This way I have the added benefit that I can even unittest my database migration scripts. But in order to do that, Phing needs access to several databases at the same time.
My first gut instinct was to put all the configuration for all four databases in build.properties
and have Phing simply generate application.xml
and phpunit.xml
. But, it feels eh, dirty to have a build system generate configuration files.
What's the best solution here? Or should I simply duplicatie the configuration details and not worry too much?
Thoughts
I could simply duplicate them. It's only a few settings and they shouldn't change often. But I bet that when they do change, I will have forgotten about the duplication (because it happens infrequently). Shared parameters include:
- Database configuration (dev, staging, production and unittests)
- Include paths. We use some older libraries that don't work with autoloaders. So far we have partially solved this with an intelligent auto-prepend file.
- A few webservice API credentials
Source: (StackOverflow)
I'm trying to check if a directory or file exists in Phing but I cannot even get the basics to work.
For example:
<project name="test" default="help" basedir="./">
<target name="clean" description="Deletes directory">
<available file="/testy" type="dir" property="dir.Exists" />
<if>
<isset property="dir.Exists"/>
<then>
<echo>Yep</echo>
</then>
</if>
</target>
<phingcall target="clean" />
</project>
I get a weird error:
Error reading project file [wrapped: \build.xml:22:18: Error initializing nested
element <echo> [wrapped: phing.tasks.system.IfTask doesn't support the 'echo'
creator/adder.]]
Ultimately I wanted to add a conditional yes/no to proceed if a directory exists.
ps. The error has nothing to do with "nested element echo" as far as I can tell because if I remove the echo it still sends the same error, in fact I think this is a default syntax related error message or something.
Source: (StackOverflow)
<?xml version="1.0" ?>
<project name="first" basedir="." default="build-skeleton">
<property name="dirName" value="module" />
<property name="fileName" value="config" />
<target name="build-skeleton" description="Making folders">
<mkdir dir="./${dirName}/Block" />
<touch file="./${dirName}/etc/${fileName}.xml" />
</target>
</project>
phing -f mage_module.xml -DdirName=moduleX,fileName=config
phing -f mage_module.xml -DdirName=moduleX fileName=config
Both throw an error - no surprise there.
Is it possible to set multiple properties in Phing via command line?
Source: (StackOverflow)
In my build script I'm trying to output the date and SVN revision number to a file in the build directory. I would like the date and revision number on separate line, but can't get a linebreak to output to the file. I've tried all sorts of methods:
<echo file="${build.dir}\build.txt">DATE = ${DATE} \r\n \\\r\\\n PHP_EOL</echo>
<echo msg="DATE: ${DATE} \r\n \\\r\\\n PHP_EOL 0x0D0A SVN revision: ${svn.lastrevision} . PHP_EOL" file="${build.dir}\build.txt" append="true" />
Has anyone else managed to get a linebreak through to file with Phing? I've looked at the code in phing, and it uses fwrite. I can only guess the strings in my build.xml are getting escaped in some way before being handled by fwrite?
I guess I may have to resort to using ExecTask?
Source: (StackOverflow)
I'm in the middle of my first ever stab at setting up Jenkins to build and run unit tests /code coverage with my CakePHP project. So far I have successfully got Jenkins fetching and building automatically from my BitBucket repository - a small victory in itself.
Next thing I want to happen is for the unit tests to run and code coverage reports to be populated.
Here is my build.xml, which is being executed in Jenkins with the (only) build command phing -f $WORKSPACE/build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="Consumer Love" default="phpunit">
<target name="phpunit">
<exec command="cake test app --coverage-clover logs/reports/clover.xml"></exec>
</target>
</project>
I think the issue is that when you run cake test app
it asks for a prompt of which specific tests you want to run, I have been unable to figure out a method to run all of my CakePHP app unit tests.
Source: (StackOverflow)