Pro PHP- Patterns, Frameworks, Testing and More

(vip2019) #1
CHAPTER 8 ■ TESTING, DEPLOYMENT, AND CONTINUOUS INTEGRATION^117

>

<fileset refid="codefiles" />
</copy>
</target>

<target name="deploy" depends="try">
<copy
todir="/usr/local/www/www.example.com/document_root"
overwrite="true"
>
<fileset refid="codefiles" />
</copy>
</target>

</project>

The first part of the file is the <project> element. This defines the name of the project,
where the source files are located, and the default target to call if Phing is invoked without any
arguments.
Next, you define a set of files with the <fileset> element and give it an id alias for use later.
You use ** to indicate a recursive include; a single * would not be recursive. This creates a sort
of array of code files that will be used by copy commands later.
Then you create the set of four targets: get, test, try, and deploy. These targets have
various dependencies, which will be called automatically before the target is run. For example,
if you were to call phing deploy, all the targets would be called, because Phing would walk the
entire dependency tree back to the get target.
The get target uses the <svnupdate> element to ensure that the checkout is up-to-date.
This element is provided by the PEAR package VersionControl_SVN.

■Caution The <svnupdate> element is experimental. If you encounter an issue with the Subversion
checkout not updating properly, use <exec command="svn update" /> instead.

PHPUnit is invoked in the test target. At the time of writing, Phing does not support PHPUnit
test suites, and will instead compile its own test counters and other information when you use
the <batchtest> element. It does this by using a fileset to locate all files ending in Test.php.
Your DemoTest.php file will be found and run. If any tests fail, the target will fail, and as a result,
the tasks try and deploy will not occur, as they depend on test. The printsummary attribute will
give you some extra information about the test success when you run the phing command.
Next, you need to define copy commands for try and deploy. These should reference only
the code files and copy them to your web root directories.
To use your Phing build file, simply type phing at the command line. Since try is the default,
you will see get, test, and then try run, in that order. The output should look something like
the following:

McArthur_819-9C08.fm Page 117 Friday, February 22, 2008 9:06 AM

Free download pdf