Prev | Next |
This chapter provides an overview of Continuous Integration summarizing the technique and its application with PHPUnit.
Continuous Integration is a software development practice where members of a team integrate their work frequently, usually each person integrates at least daily, leading to multiple integrations per day. Each integration is verified by an automated build (including test) to detect integration errors as quickly as possible. Many teams find that this approach leads to significantly reduced integration problems and allows a team to develop cohesive software more rapidly. | ||
--Martin Fowler |
Continuous Integration demands a fully automated and reproducible build, including testing, that runs many times a day. This allows each developer to integrate daily thus reducing integration problems. While this can be achieved by setting up a cronjob that makes a fresh checkout from the project's source code repository at regular intervals, runs the tests, and publishes the results, a more comfortable solution may be desired.
Atlassian Bamboo is a Continuous Integration (CI) server that assists software development teams by providing automated building and testing of software source-code status, updates on successful/failed builds, and reporting tools for statistical analysis.
The following example assumes that the Bamboo distribution archive has
been unpacked into /usr/local/Bamboo
.
cd /usr/local/Bamboo
Edit the webapp/WEB-INF/classes/bamboo-init.properties
file.
Optionally install the bamboo-checkstyle
plugin.
./bamboo.sh start
Open http://localhost:8085/
in your webbrowser.
Follow the guided installation instructions.
Configure Apache Ant as a Builder in the Administration panel.
Bamboo is now configured and we can set up a project plan. First we need
a project, though. For the purpose of this example lets assume we have a
copy of the Money
sample that ships with PHPUnit in a
Subversion repository (file:///var/svn/money
).
Together with the *.php
files we also have the
following Apache Ant build script (build.xml
) in the
repository.
Example 20.2: build.xml
<project name="Money" default="build">
<target name="clean">
<delete dir="${basedir}/build"/>
</target>
<target name="prepare">
<mkdir dir="${basedir}/build"/>
<mkdir dir="${basedir}/build/logs"/>
</target>
<target name="phpcs">
<exec dir="${basedir}"
executable="phpcs"
output="${basedir}/build/logs/checkstyle.xml"
failonerror="false">
<arg line="--report=checkstyle ." />
</exec>
</target>
<target name="phpunit">
<exec dir="${basedir}" executable="phpunit" failonerror="true">
<arg line="--log-xml ${basedir}/build/logs/phpunit.xml
--coverage-clover ${basedir}/build/logs/clover.xml
--coverage-html ${basedir}/build/coverage
MoneyTest" />
</exec>
</target>
<target name="build" depends="clean,prepare,phpcs,phpunit"/>
</project>
Now that we have a project, we can create a plan for it in Bamboo.
Open http://localhost:8080/
in your webbrowser.
Follow the guided "Create a Plan" instructions.
In step 3 of "Create a Plan", check the "The build will produce test results" and "Clover output will be produced" options and provide the paths to the XML files produced by PHPUnit.
If you installed the bamboo-checkstyle
plugin also check the "CheckStyle output will be produced" option and provide the path of the XML file produced by PHP_CodeSniffer.
In step 5 of "Create a Plan", set up an artifact for the HTML files (*.*
, build/coverage
) that PHPUnit produces.
CruiseControl is a framework for continuous build processes and includes, but is not limited to, plugins for email notification, Apache Ant, and various source control tools. A web interface is provided to view the details of the current and previous builds.
The following example assumes that CruiseControl has been installed into
/usr/local/cruisecontrol
.
cd /usr/local/cruisecontrol
mkdir -p projects/Money/build/logs
cd projects/Money
svn co file:///var/svn/money source
Edit the build.xml
file.
Example 20.3: projects/Money/build.xml
<project name="Money" default="build" basedir=".">
<target name="checkout">
<exec dir="${basedir}/source/" executable="svn">
<arg line="up"/>
</exec>
</target>
<target name="test">
<exec dir="${basedir}/source" executable="phpunit" failonerror="true">
<arg line="--log-xml ${basedir}/build/logs/phpunit.xml MoneyTest"/>
</exec>
</target>
<target name="build" depends="checkout,test"/>
</project>
cd /usr/local/cruisecontrol
Edit the config.xml
file.
Example 20.4: config.xml
<cruisecontrol>
<project name="Money" buildafterfailed="false">
<plugin
name="svnbootstrapper"
classname="net.sourceforge.cruisecontrol.bootstrappers.SVNBootstrapper"/>
<plugin
name="svn"
classname="net.sourceforge.cruisecontrol.sourcecontrols.SVN"/>
<listeners>
<currentbuildstatuslistener file="logs/${project.name}/status.txt"/>
</listeners>
<bootstrappers>
<svnbootstrapper localWorkingCopy="projects/${project.name}/source/"/>
</bootstrappers>
<modificationset>
<svn localWorkingCopy="projects/${project.name}/source/"/>
</modificationset>
<schedule interval="300">
<ant
anthome="apache-ant-1.7.0"
buildfile="projects/${project.name}/build.xml"/>
</schedule>
<log dir="logs/${project.name}">
<merge dir="projects/${project.name}/build/logs/"/>
</log>
<publishers>
<currentbuildstatuspublisher
file="logs/${project.name}/buildstatus.txt"/>
<email
mailhost="localhost"
buildresultsurl="http://cruise.example.com/buildresults/${project.name}"
skipusers="true"
spamwhilebroken="true"
returnaddress="project@example.com">
<failure address="dev@lists.example.com" reportWhenFixed="true"/>
</email>
</publishers>
</project>
</cruisecontrol>
Now we can (re)start the CruiseControl server.
./cruisecontrol.sh
Open http://localhost:8080/
in your webbrowser.
phpUnderControl is an
extension for CruiseControl that integrates several PHP development tools,
such as PHPUnit for testing,
PHP_CodeSniffer
for static
code analysis, and PHPDocumentor
for API
documentation generation. It comes with a powerful command-line
tool that can, among other things, automatically create CruiseControl's
XML configuration files for your project. The following example assumes
that CruiseControl has been installed into
/usr/local/cruisecontrol
.
pear install --alldeps phpunit/phpUnderControl
phpuc install /usr/local/cruisecontrol
phpuc project --version-control svn
--version-control-url file:///var/svn/money
--test-case MoneyTest
--test-file MoneyTest.php
--test-dir .
--project-name Money
/usr/local/cruisecontrol
The above command creates the project directory and the project's
build.xml
configuration file, performs the initial
checkout from the source repository, and adds the new project to the
global config.xml
configuration file. Now we can
(re)start the CruiseControl server.
cd /usr/local/cruisecontrol
./cruisecontrol.sh
Open http://localhost:8080/
in your webbrowser.
Prev | Next |
assertArrayHasKey()
assertClassHasAttribute()
assertClassHasStaticAttribute()
assertContains()
assertContainsOnly()
assertEmpty()
assertEqualXMLStructure()
assertEquals()
assertFalse()
assertFileEquals()
assertFileExists()
assertGreaterThan()
assertGreaterThanOrEqual()
assertInstanceOf()
assertInternalType()
assertLessThan()
assertLessThanOrEqual()
assertNull()
assertObjectHasAttribute()
assertRegExp()
assertStringMatchesFormat()
assertStringMatchesFormatFile()
assertSame()
assertSelectCount()
assertSelectEquals()
assertSelectRegExp()
assertStringEndsWith()
assertStringEqualsFile()
assertStringStartsWith()
assertTag()
assertThat()
assertTrue()
assertType()
assertXmlFileEqualsXmlFile()
assertXmlStringEqualsXmlFile()
assertXmlStringEqualsXmlString()
Copyright © 2005-2010 Sebastian Bergmann.