<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dominique Stender &#187; Test Automation</title>
	<atom:link href="http://www.st-webdevelopment.com/tag/test-automation/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.st-webdevelopment.com</link>
	<description>Good software is only the beginning...</description>
	<lastBuildDate>Wed, 14 Apr 2010 17:50:37 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>HOWTO: Continuous integration for PHP, pt. 4</title>
		<link>http://www.st-webdevelopment.com/test-automation/2009/11/howto-continuous-integration-php-pt-4/</link>
		<comments>http://www.st-webdevelopment.com/test-automation/2009/11/howto-continuous-integration-php-pt-4/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 02:51:14 +0000</pubDate>
		<dc:creator>Dominique</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Test Automation]]></category>
		<category><![CDATA[continuous integration]]></category>
		<category><![CDATA[deployment]]></category>
		<category><![CDATA[phing]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[software build]]></category>
		<category><![CDATA[subversion]]></category>

		<guid isPermaLink="false">http://www.st-webdevelopment.com/?p=136</guid>
		<description><![CDATA[In the fourth article in the series on continuous integration for PHP Dominique Stender showcases how to run Subversion updates automatically from phing and run a set of tests if a new revision was retrieved from Subversion. ]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-137" title="clouds" src="http://www.st-webdevelopment.com/wp-content/uploads/2009/11/clouds.jpg" alt="clouds" width="190" height="400" />This is the fourth article in my series about continuous integration for PHP. You might want to read the <a title="First article in my continuous integration series, covering basic understanding" href="/test-automation/2009/11/howto-setting-continous-integration-php/" target="_self">first</a>, <a title="Second article in my continuous integration series, covering the server installation" href="/test-automation/2009/11/howto-continuous-integration-php-pt-2/" target="_self">second</a> and <a title="Third article in my series on continuous integration for PHP" href="/test-automation/2009/11/howto-continuous-integration-php-pt-3/" target="_self">third article</a> prior to this.</p>
<p>We're getting closer and closer to full test automation and continuous integration. The last article introduced you to how to write <a title="PHPUnit - unittesting for PHP" href="http://www.phpunit.de" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.phpunit.de?referer=');">PHPUnit </a>tests for <a title="Selenium RC - automated frontend testing" href="http://seleniumhq.org/projects/remote-control/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/seleniumhq.org/projects/remote-control/?referer=');">SeleniumRC </a>so that we can test website frontends through PHPUnit. After that we wrote our own phing build script that ran our backend as well as the frontend tests automatically, generated an code coverage report based on Xdebug as well as an comprehensive APIDoc based on PHPDoc comments.</p>
<p>The phing build script we used for this - test.xml - was executed manually by calling</p>
<pre>phing -f test.xml</pre>
<p>on the command line. Everything happened on the development virtual host.</p>
<p>The next logical step is to automate this and perform the additional tasks required to run continuous integration.</p>
<p>The first step is to do a manual svn checkout on the integration virtual host, so we have setup that is identical to the development virtual host.</p>
<p>Now, what the automation will have to do is a Subversion update of the integration virtual host in order to retrieve the latest copy. If the revision changes in that process (that is, if we indeed fetched newer files from Subversion) we again run the tests and generate the reports. If all tests succeed we can safely assume that we have a running system, and we can decide to create a tarball from it or update the staging system for our project manager / client to check it out. On the other hand, if a test fails we'd like to be notified by email.</p>
<p>This is exactly what a second phing build script will do.</p>
<p><span id="more-136"></span></p>
<h4>Introducing more flexibility</h4>
<p>Before we can do all that, we need to make a small but very important change to the Selenium RC test case. The setUp() method of out tests/TestForm.php file configures SeleniumRC so that it points to http://integration.local which is our development environment. This means that no matter where we run the frontend tests, this test would always test our development environment! Clearly not what we want.</p>
<p>If the developer runs the test manually (by executing phing -f test.xml on the commandline), the development environment has to be used. For the automation, the integration host http://integrate.integration.local has to be used.</p>
<p>We accomplish this by changing the setUp() method to this:</p>
<pre class="php">function setUp() {
  // determine hostname based on phing property
  $startDir = Phing::getProperty('application.startdir');
  preg_match('/\/(default|integration|demo)/', $startDir, $vhostMainDir);

  switch($vhostMainDir[1]) {
    case 'default':
      $browserUrl = 'http://integration.local/';
      break;

    case 'integration':
      $browserUrl = 'http://integrate.integration.local/';
      break;

    case 'demo':
      $browserUrl = 'http://demo.integration.local/';
      break;

    default:
  } // end: switch

  $this-&gt;screenshotUrl    = $browserUrl . 'reports/selenium';
  $this-&gt;screenshotPath    = $_ENV['PWD'] . '/../reports/selenium';
  $this-&gt;setBrowser('*firefox');
  $this-&gt;setBrowserUrl($browserUrl);
} // end: function setUp()</pre>
<p>We retrieve the application.startdir property and with this information we can decide in which environment we run to set the browser URL and the screenshot path correctly.</p>
<h4>Committing and retrieve everything to Subversion.</h4>
<p>With that flexibility issue in the test out of the way we can commit the whole development environment /var/www/vhosts/default to Subversion:</p>
<pre>svn import /var/www/vhosts/default https://your.subversion.server/repository/path/trunk
svn checkout --force https://your.subversion.server/repository/path/trunk /var/www/vhosts/default</pre>
<p>Your development environment now is connected to the subversion repository.</p>
<p>Next, you have to do another svn checkout from the same repository URL, this time to the integration environment.</p>
<pre>svn checkout --force https://your.subversion.server/repository/path/trunk /var/www/vhosts/integration</pre>
<p>Now the integration environment is identical to the development environment.</p>
<blockquote><p>Note that the virtual host configuration file for apache will not be overwritten, since the filenames are different. However the integration environment now contains two .conf files for apache. Since only the correct one is linked to /etc/apache2/sites-available, no harm is done though.</p></blockquote>
<h4>The continuous integration build script.</h4>
<p>The single addition between our manual tests from the test.xml phing build file and the continuous integration is another phing build file that you will find at buildScripts/updateAndBuild.xml. If you open it in an editor it will look like this.</p>
<pre class="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;project basedir="." default="runTests" name="updateWorkingCopy"&gt;
  &lt;property name="demoDir"      value="/var/www/vhosts/demo" /&gt;
  &lt;property name="baseDir"      value="/var/www/vhosts/integration" /&gt;
  &lt;property name="htdocsDir"    value="${baseDir}/htdocs" /&gt;
  &lt;property name="testDir"      value="${baseDir}/tests/" /&gt;
  &lt;property name="reportDir"    value="${htdocsDir}/reports" /&gt;
  &lt;property name="seleniumDir"  value="${reportDir}/selenium" /&gt;
  &lt;property name="masterFile"   value="updateAndBuild" /&gt;
  &lt;property name="buildVersion" value="1.6.1" /&gt;
  &lt;property name="srcDir"       value="/var/www/vhosts/integration/htdocs" /&gt;
  &lt;property name="svnUser"      value="your_svn_user" /&gt;
  &lt;property name="svnPass"      value="your_svn_password" /&gt;

  &lt;!--fetch current revision of working copy --&gt;
  &lt;target name="getOriginalRevision"&gt;
    &lt;svnlastrevision workingcopy="${baseDir}" propertyname="svnOriginalRevision" /&gt;
    &lt;echo msg="Current revision of this working copy: ${svnOriginalRevision}" /&gt;
  &lt;/target&gt;

  &lt;!-- update local working copy --&gt;
  &lt;target name="svnUpdate"&gt;
    &lt;svnupdate username="${svnUser}" password="${svnPass}" nocache="true" todir="${baseDir}" /&gt;
  &lt;/target&gt;

  &lt;!-- fetch revision of working copy again --&gt;
  &lt;target name="getCurrentRevision" depends="svnUpdate"&gt;
    &lt;svnlastrevision workingcopy="${baseDir}" propertyname="svnCurrentRevision" /&gt;
    &lt;echo msg="Revision of this working copy after svn update: ${svnCurrentRevision}" /&gt;
  &lt;/target&gt;

  &lt;!-- create the tarball from the integration VHost--&gt;
  &lt;target name="tar"&gt;
    &lt;echo msg="Creating archive..." /&gt;
    &lt;tar destfile="${baseDir}/builds/build-${buildVersion}.r${svnCurrentRevision}.tar.gz" compression="gzip"&gt;
      &lt;fileset dir="${htdocsDir}"&gt;
        &lt;include name="**" /&gt;
        &lt;exclude name="reports/**" /&gt;
      &lt;/fileset&gt;
    &lt;/tar&gt;
    &lt;echo msg="Build copied and compressed into directory!" /&gt;
  &lt;/target&gt;

  &lt;!-- updates the demo VHost after all tests have succeeded --&gt;
  &lt;target name="updateDemo"&gt;
    &lt;!-- change baseDir to demoDir --&gt;
    &lt;property name="baseDir" value="${demoDir}" override="true" /&gt;
    &lt;phingcall target="svnUpdate" /&gt;
  &lt;/target&gt;

  &lt;!-- compare original and current working copy revisions --&gt;
  &lt;target name="runTests"  depends="getOriginalRevision,getCurrentRevision"&gt;
    &lt;if&gt;
      &lt;equals arg1="${svnOriginalRevision}" arg2="${svnCurrentRevision}" /&gt;
      &lt;then&gt;
        &lt;echo msg="Working copy is up to date." /&gt;
      &lt;/then&gt;
      &lt;else&gt;
        &lt;echo msg="Updated working copy from SVN, starting integration tests." /&gt;
        &lt;phing phingfile="test.xml" haltonfailure="true" /&gt;
        &lt;phingcall target="tar" /&gt;
        &lt;phingcall target="updateDemo" /&gt;
      &lt;/else&gt;
    &lt;/if&gt;
  &lt;/target&gt;
&lt;/project&gt;</pre>
<p>Let's go through this script step by step.</p>
<ol>
<li>The target &lt;getOriginalRevision&gt; gets called first.<br />
Thankfully phing provides a ready-made task to retrieve the Subversion revision of a given path. We store that revision in the property ${svnOriginalRevision}.</li>
<li>Next, the &lt;svnUpdate&gt; target performs a Subversion update on the whole integration environment, ensuring we get any updates that have been committed since the last run. Since this environment will never be edited there will never be any merge conflicts.</li>
<li>Then the&lt; svnCurrentRevision&gt; target fetches the Subversion revision number of the integration environment again and stores it in a property, this time in ${svnCurrentRevision}. Note that this target is identical to &lt;getOriginalRevision&gt;, except for the property used.</li>
<li>After we have ensured that the integration environment is up to date, the main target &lt;runTests&gt; compares the ${svnOriginalRevision} with ${svnCurrentRevision} to check if a newer version has arrived. If not, this continuous integration loop stops. No need to test again what was already tested.</li>
<li>If the execution did not stop - that is, if a newer source code version has arrived - we use the &lt;phing&gt; task to execute the test.xml build file we introduced in the <a title="Third article in my series on continuous integration for PHP" href="/test-automation/2009/11/howto-continuous-integration-php-pt-3/" target="_self">third part of this series</a>.<br />
The buildAndUpdate.xml uses the same properties as the test.xml and because of that the latter will now run in the integration environment.</li>
<li>In case the test.xml script runs through without error a tarball is created automatically, containing everything in the htdocs directory.</li>
<li>Last not least we perform a SVN update on the demo environment.</li>
</ol>
<blockquote><p>Note that the test.xml build file will now send an email if one of the tests fails!</p>
<p>This is due to the fact that the updateAndBuild.xml sets the ${masterFile} property to a value that causes an &lt;if&gt; task in test.xml (line 112) to pass. This way the developers will automatically be alerted if the current revision in the integration environment is broken. If the test.xml is executed manually the if-condition will not apply and no mail is sent.</p></blockquote>
<h4>Testing the phing script.</h4>
<p>You can direct your SSH shell to /var/www/vhosts/integration and execute</p>
<pre>phing -f buildScripts/updateAndBuild.xml</pre>
<p>but this will not do much good since the integration environment is up to date.</p>
<p>What I would recommend is to create a new file in the development environment /var/www/vhosts/default and fill it with some arbitrary text, only to add and commit that file to Subversion. Then return to the integration environment and run the same command.</p>
<p>Voila! The phing script updated the integration environment, recognized the update and started all tests (this time in the integration environment). Once more, a reports folder has been created (again in the integration environment) and filled. A new folder /var/www/vhosts/integration/builds will have been created, containing a .tar.gz file with the latest build.</p>
<blockquote><p>Note that this folder may get huge very fast, depending on project complexity. It is probably advisable to deactivate the automatic tarball generation task for a real life environment.</p></blockquote>
<p>If you add an error to one of the tests, you should get an email. Double check the ${errorMail} property in test.xml and make sure the server can successfully sent mails if you don't.</p>
<p>The last step for you to do is to set up a cronjob to run the phing command periodically. Make sure the cron environment is forwarding the X server display and otherwise is as close as your shell environment as possible, because otherwise you will run into all sorts of issues. This is the nature of cron...</p>
<h4>This concludes my tutorial on continuous integration for PHP.</h4>
<p>Leave me a comment if you liked the series, if you have questions or suggestions for improvements. I will work on a fifth and last article about my own thoughts for possible improvements, to be published in a bit.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.st-webdevelopment.com/test-automation/2009/11/howto-continuous-integration-php-pt-4/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>HOWTO: Continuous Integration for PHP, pt. 3</title>
		<link>http://www.st-webdevelopment.com/test-automation/2009/11/howto-continuous-integration-php-pt-3/</link>
		<comments>http://www.st-webdevelopment.com/test-automation/2009/11/howto-continuous-integration-php-pt-3/#comments</comments>
		<pubDate>Thu, 26 Nov 2009 18:48:27 +0000</pubDate>
		<dc:creator>Dominique</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Test Automation]]></category>
		<category><![CDATA[continuous integration]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[phing]]></category>
		<category><![CDATA[phpunit]]></category>
		<category><![CDATA[selenium]]></category>
		<category><![CDATA[Xvfb]]></category>

		<guid isPermaLink="false">http://www.st-webdevelopment.com/?p=97</guid>
		<description><![CDATA[A detailed explanation how to combine PHPUnit, SeleniumRC and phing to create a thorough overview of a PHP project.]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-98" title="gourd" src="http://www.st-webdevelopment.com/wp-content/uploads/2009/11/gourd.jpg" alt="gourd" width="190" height="400" />This is the third article in my series about continuous integration for PHP. You might want to read the <a title="First article in my continuous integration series, covering basic understanding" href="/test-automation/2009/11/howto-setting-continous-integration-php/" target="_self">first </a>and <a title="Second article in my continuous integration series, covering the server installation" href="/test-automation/2009/11/howto-continuous-integration-php-pt-2/" target="_self">second</a> article prior to this.</p>
<p>In this article I want to introduce you to the way I run the continuous integration tests, what to run when, and where. If you're unsure how to write unittests, this will not be covered in this article but <a title="PHPUnit homepage" href="http://www.phpunit.de/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.phpunit.de/?referer=');">phpunit.de</a> has an excellent documentation section just covering <a title="How to write tests for PHPUnit" href="http://www.phpunit.de/manual/current/en/writing-tests-for-phpunit.html" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.phpunit.de/manual/current/en/writing-tests-for-phpunit.html?referer=');">how to write tests</a>. Another section is there covering <a title="How to write tests for SeleniumRC" href="http://www.phpunit.de/manual/current/en/selenium.html" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.phpunit.de/manual/current/en/selenium.html?referer=');">how to write tests for SeleniumRC</a>.</p>
<p>Let me start this article with a short summary of what we have installed in the second part: We have a pretty standard LAMP server based on Ubuntu Linux. Then there is PHPUnit for unit and regression testing as well as phing, our integration server. We added SeleniumRC as a frontend test tool, then Xvfb and Firefox to facilitate the frontend tests. xdebug is used by PHPUnit for code coverage reports and phpDocumentor will be used by phing for automatic APIdoc generation.</p>
<p>A Subversion client to fetch latest updates out of the repository completes the setup.</p>
<p>Ok, let's dig a little deeper into the filesystem structure and how to use it, shall we?</p>
<p><span id="more-97"></span>We installed three virtual hosts in apache, one for development, one for the integration and one as staging system.</p>
<div id="attachment_62" class="wp-caption aligncenter" style="width: 447px"><img class="size-full wp-image-62" title="environment" src="http://www.st-webdevelopment.com/wp-content/uploads/2009/11/environment.png" alt="My continuous integration environment" width="437" height="273" /><p class="wp-caption-text">My continuous integration environment</p></div>
<p>The whole setup is merely to demonstrate the workflow. In reality the integration and staging environment would most likely run on a separate machine, or two.</p>
<p><img class="alignleft size-full wp-image-99" title="hostStructure" src="http://www.st-webdevelopment.com/wp-content/uploads/2009/11/hostStructure.png" alt="hostStructure" width="120" height="173" />Each virtual host contains the same initial directory structure, like you see on the left. The image shows the structure of the default server (used for development).</p>
<p>You see the ./conf folder, which stores the Apache configuration file. You can add your own configuration files to this folder if you like.</p>
<p>The ./htdocs folder is what you think it is, the webserver root.</p>
<p>The ./tests and ./buildScripts folders will contain the test classes, as well as all files required by phing to build the project.</p>
<p>This layout is simple, yet effective. It cleanly separates the utilities used for testing and continuous integration from the rest of the project, thus making packaging and deployment comparatively easy.</p>
<p>In the screenshot you also see that the whole default virtual host is under revision control. Experience shows that in the end, you will want everything versioned no matter what you think initially.</p>
<p>Last not least the screenshot shows the other two virtual hosts 'integration' and 'demo', both being under version control as well - but more on that later.</p>
<h4>Ok, are you ready to write some tests?</h4>
<p>Some of the scripts discussed below are quite long, so I will not post them here in the blog in their full length. You can get a <a href="http://www.st-webdevelopment.com/wp-content/uploads/2009/11/vhost.zip">continuous integration test file setup</a> (.zip file) for ease of use.</p>
<p>We start with a simple file which we put in default/htdocs/class.hello.php:</p>
<pre name="code" class="php">&lt;?php
 class HelloWorld {
   public function hello() {
     return 'Hello World';
   } // end: function hello()
 } // end: class HelloWorld
?&gt;</pre>
<p>As you see the class HelloWorld contains a single method 'hello' without any parameters that returns the famous 'Hello World'. The corresponding unittest is equaly simple. We create a second file in default/tests/Test.HelloWorld.php:</p>
<pre name="code" class="php">&lt;?php
require_once('PHPUnit/Framework.php');
include_once('../htdocs/class.hello.php');

class TestHelloWorld extends PHPUnit_Framework_TestCase {
  private $ciTestObj = null;

  public function setUp() {
    $this-&gt;ciTestObj = new HelloWorld();
  } // end: function setUp()

  public function testHello() {
    $this-&gt;assertEquals($this-&gt;ciTestObj-&gt;hello(), 'Hello World');
  } // end: function testHello()
} // end: class TestHelloWorld
?&gt;</pre>
<p>Now, the property $ciTestObj contains an instance of the test object which is our HelloWorld class from the first script. The only test we perform is an assertEquals() call that compares the return value of the HelloWorld::hello() method with the static string 'Hello World'.</p>
<p>Save the file and connect to the continuous integration server using your favorite SSH client. Change into the tests directory and execute phpunit:</p>
<pre>phpunit Test.HelloWorld.php</pre>
<p>You should get a result similar to this:</p>
<pre>PHPUnit 3.4.2 by Sebastian Bergmann.
.
Time: 1 second
OK (1 test, 1 assertion)</pre>
<p>Hooray, the test passed. Our class behaves as expected.</p>
<h4>The second step will be to run a frontend test in SeleniumRC.</h4>
<p>Usually you would create a test in Firefox with SeleniumIDE set to write PHPUnit test files instead of the html default. However for a quick success I recommend copy-pasting the test that I prepared.</p>
<blockquote><p>Before we attempt to run SeleniumRC in the continuous integration server, configure your SSH client to allow X forwarding. If it is currently inactive, enable it. The test won't run without that. Double check your settings are correct.</p></blockquote>
<p>Ok, once more we start with our test subject. This time it is a very simple html page with a form. The form doesn't do anything except filling the form fields with the values you entered before submit. Create a file default/htdocs/form.php with the following content:</p>
<pre name="code" class="xhtml">&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US"&gt;
&lt;head&gt;
  &lt;title&gt;Testable form&lt;/title&gt;
  &lt;meta http-equiv="content-type" content="text/html; charset=utf-8" /&gt;
  &lt;style type="text/css"&gt;
    body {background-color: #fff;}
    label {
      display: block;
      float: left;
      min-width: 140px;
      padding-right: 5px;
    }
    input,textarea {
      border: 1px inset;
      margin: 5px 0;
    }
    textarea {height: 150px;}
    input[type=submit] {border: 1px outset;}
   .long {width: 300px;}
  &lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
  &lt;h2&gt;Selenium RC test form&lt;/h2&gt;
  &lt;p&gt;
    This form does have absolutelly no purpose other than being a test subject for selenium RC.
  &lt;/p&gt;
  &lt;form action="&lt;?php echo $PHP_SELF; ?&gt;" method="post"&gt;
    &lt;label for="firstname"&gt;firstname, lastname: *&lt;/label&gt;&lt;input type="text" name="firstname" value="&lt;?php echo $_POST['firstname']; ?&gt;" /&gt; &lt;input type="text" name="lastname" value="&lt;?php echo $_POST['lastname']; ?&gt;" /&gt;&lt;br /&gt;
    &lt;label for="email"&gt;email: *&lt;/label&gt;&lt;input type="text" name="email" value="&lt;?php echo $_POST['email']; ?&gt;" /&gt;&lt;br /&gt;
    &lt;label for="url"&gt;homepage:&lt;/label&gt;&lt;input type="text" name="url" value="&lt;?php echo $_POST['url']; ?&gt;" /&gt;&lt;br /&gt;
    &lt;label for="subject"&gt;subject: *&lt;/label&gt;&lt;input type="text" name="subject" value="&lt;?php echo $_POST['subject']; ?&gt;" /&gt;&lt;br /&gt;
    &lt;label for="comment"&gt;your message: *&lt;/label&gt;&lt;textarea name="comment"&gt;&lt;?php echo $_POST['comment']; ?&gt;&lt;/textarea&gt;&lt;br /&gt;
    &lt;label for=""&gt;&amp;nbsp;&lt;/label&gt;&lt;input type="submit" value="submit" /&gt;
  &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>Open it in your browser, just to confirm that it is working. If you followed this howto step by step, http://integration.local/form.php should work just fine. You should do the same from the command line on the server to see if local access is also correct:</p>
<pre>lynx http://integration.local/form.php</pre>
<p>If that is not working, go back to the <a title="Second article on continuous integration for PHP" href="http://www.st-webdevelopment.com/test-automation/2009/11/howto-continuous-integration-php-pt-2/" target="_self">second part</a> of this series and check the settings in the hosts files. However if it does, we can write our test for the subject. Open a new file in default/tests/TestForm.php and paste this:</p>
<pre name="code" class="php">&lt;?php
require_once('PHPUnit/Extensions/SeleniumTestCase.php');

class TestForm extends PHPUnit_Extensions_SeleniumTestCase {
  protected $captureScreenshotOnFailure = TRUE;
  protected $screenshotUrl = 'http://integration.local/reports/selenium';

  function setUp() {
    $this-&gt;screenshotPath = $_ENV['PWD'] . '/../reports/selenium';
    $this-&gt;setBrowser('*firefox');
    $this-&gt;setBrowserUrl('http://integration.local/');
  } // end: function setUp()

  function testFormSubmit() {
    $this-&gt;open('/form.php');
    $this-&gt;waitForPageToLoad('30000');
    $this-&gt;type('firstname', 'SeleniumRC');
    $this-&gt;type('lastname', 'Testautomation');
    $this-&gt;type('email', 'selenium@example.com');
    $this-&gt;type('url', 'http://seleniumhq.com');
    $this-&gt;type('subject', 'Test for Selenium RC');
    $this-&gt;type('comment', 'This is just to test Selenium RC in a continuous integration environment with Phing and PHPUnit.');

    $this-&gt;click('//input[@value="submit"]');
    $this-&gt;waitForPageToLoad('30000');
    $this-&gt;assertEquals('SeleniumRC', $this-&gt;getValue('firstname'));
    $this-&gt;assertEquals('Testautomation', $this-&gt;getValue('lastname'));
    $this-&gt;assertEquals('selenium@example.com', $this-&gt;getValue('email'));
    $this-&gt;assertEquals('http://seleniumhq.com', $this-&gt;getValue('url'));
    $this-&gt;assertEquals('Test for Selenium RC', $this-&gt;getValue('subject'));
    $this-&gt;assertEquals('This is just to test Selenium RC in a continuous integration environment with Phing and PHPUnit.', $this-&gt;getValue('comment'));
  } // end: function testFormSubmit()
} //end: class TestForm
?&gt;</pre>
<blockquote><p>Note that before 30th of November 2009 the above code contained the wrong hostnames for both TestFor::screenShotUrl and the setBrowserUrl() call. Sorry for this! The .zip file has been corrected, as well.</p></blockquote>
<p>This PHPUnit test will start a firefox browser on the server, hit the form.php on the server and fill out the form. It will submit the form and compare the values in the form fields with those entered previously with assertions.</p>
<p>To check this we run PHPUnit again. Since this is a frontend test it required Xvfb (our X server) and SeleniumRC to run.</p>
<pre>Xvfb :1 -screen 0 1280x1024x24 &amp;
env DISPLAY=:1 java -jar /var/www/SeleniumRC/selenium-server-1.0.1/selenium-server.jar  &amp;</pre>
<p>Ignore all errors and warnings that Xvfb will probably throw for now - those will be interesting only if the tests fail. It takes some time for both daemons to start up, but after a bit of patience we can  run PHPUnit:</p>
<pre>phpunit TestForm.php</pre>
<p>The first thing you will notice is that it takes some time before PHPUnit is doing anything - that is while firefox starts - but then it is cluttering the screen with output (actually most of it doesn't come from PHPUnit but from SeleniumRC but you get the point).</p>
<p>The important part is that the output ends with something like this:</p>
<pre>.
Time: 24 seconds
OK (1 test, 6 assertions)</pre>
<p>You already know what this means... the test passed, the form works as expected. Just to clarify once again: We just tested a website in Firefox by writing and executing a PHPUnit test class.</p>
<p>Now you will want to stop both Xvfb and SeleniumRC in order to continue:</p>
<pre>kill -TERM %2
kill -TERM %1</pre>
<h4>Step three: Automate all tests with phing.</h4>
<p>Now that the PHPUnit tests run independently it is time for some more automation with phing, our integration server. Check out the test.xml file in the buildScripts folder contained in the <a href="http://www.st-webdevelopment.com/wp-content/uploads/2009/11/vhost.zip">.zip file</a> that contains the test setup. It is over 100 lines long so I will not post it here. If you're familiar with the <a title="Getting started with phing, the php build server" href="http://phing.info/docs/guide/stable/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/phing.info/docs/guide/stable/?referer=');">file structure of a phing build script</a>, you will see that the file consists of a couple of targets which will implement the following workflow:</p>
<ol>
<li>Removing a htdocs/report folder (more on that in a bit)<br />
&lt;target name="prepare"&gt;</li>
<li>Prepare a (temporary) xdebug code coverage database<br />
&lt;target name="coveragePrepare"&gt;</li>
<li>Start Xvfb and SeleniumRC, just like we did above<br />
&lt;target name="setUp"&gt;</li>
<li>Generate an APIdoc using phpDocumentor<br />
&lt;target name="doc"&gt;</li>
<li>Running all PHPUnit tests inside the tests folder<br />
&lt;target name="unittest"&gt;</li>
<li>Generating the code coverage report<br />
&lt;target name="coverageReport"&gt;</li>
<li>Shutting down Xvfb and SeleniumRC again<br />
(inside the "main" target)</li>
<li>In some condition (which we discuss in a bit) the build script will send a mail notification that the build tests have failed.</li>
</ol>
<p>But first let's do the fun thing, run the script. Once piece of advice though: You might want to go to line no 23 of the test.xml script and set your own mail Id. While running the script in this constellation the mail will not be used but better cover this now than wonder why mails are not reaching you later.</p>
<p>So go ahead... change into the default/buildScripts directory and execute</p>
<pre>phing -f test.xml</pre>
<p>Phing will read in the .xml file and perform all the tasks mentioned above in that order. Once the script has finished, check the htdocs folder. Now there is a reports subfolder that hasn't been there before. This is where all test results are stored. To be specific:</p>
<ol>
<li>Your PHPUnit test results
<p>http://integration.local/reports/phpunit/</li>
<li>A code coverage report
<p>http://integration.local/reports/coverage/</li>
<li>PHP APIDoc
<p>http://integration.local/reports/apidocs/</li>
</ol>
<p>There is an additional folder http://integration.local/reports/selenium/ which contains the STDOUT and STDERR logs generated by SeleniumRC but that is really only of interest if something goes wrong in the execution of the frontend tests.</p>
<p>Open each of the URLs above in your browser to see what you got. I believe it is pretty impressive.</p>
<h4>Final note on the text.xml file.</h4>
<p>To avoid this article getting even longer, I'll cut things short. The test.xml phing build script is meant to be run by the developer, and manually so. It will only work in the 'default' virtual host unless you change the properties on top. But please keep them as they are for now, as in the fourth article of this series I'll explain how to use another phing build file to automate all things once and for all.</p>
<p>The idea behind the test.xml build file is to make it easy for the developer to get a thorough overview of his working copy - without the need to commit everything just to see what is breaking.</p>
<p>I can only motivate you to try and play around with things. One cool detail for example is that PHPUnit will automatically make a screenshot from the website in firefox whenever a SeleniumRC test assertion fails. So break one assertion and visit the phpunit report file in your browser and you will find a report on what failed along with a URL (sadly it is not linked).</p>
<p>This concludes the third part of the continuous integration for PHP series. Come back in a couple of days for details on <a title="Fourth article in my series on continuous integration for PHP" href="/test-automation/2009/11/howto-continuous-integration-php-pt-4/" target="_self">how to automate the build process</a> in the integration virtual host.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.st-webdevelopment.com/test-automation/2009/11/howto-continuous-integration-php-pt-3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>HOWTO: Continuous Integration for PHP, pt. 2</title>
		<link>http://www.st-webdevelopment.com/test-automation/2009/11/howto-continuous-integration-php-pt-2/</link>
		<comments>http://www.st-webdevelopment.com/test-automation/2009/11/howto-continuous-integration-php-pt-2/#comments</comments>
		<pubDate>Sun, 22 Nov 2009 04:53:10 +0000</pubDate>
		<dc:creator>Dominique</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Test Automation]]></category>
		<category><![CDATA[continuous integration]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[Linux installation]]></category>
		<category><![CDATA[phing]]></category>
		<category><![CDATA[phpunit]]></category>
		<category><![CDATA[selenium]]></category>
		<category><![CDATA[Xvfb]]></category>

		<guid isPermaLink="false">http://www.st-webdevelopment.de/?p=76</guid>
		<description><![CDATA[A step-by-step guide how to install a continuous integration environment for PHP based on Ubuntu Linux, PHPUnit, phing, phpDocumentor, Xvfb and SeleniumRC]]></description>
			<content:encoded><![CDATA[<p>This is the second in the series of articles on continuous integration for PHP. You might want to start reading the <a title="First article on continuous integration for PHP" href="/test-automation/2009/11/howto-setting-continous-integration-php/" target="_self">first article</a>, covering the basic tools in the setup before you continue here.</p>
<p>Here I will give you a step-by-step guide how to set up a LAMP server with all the necessary tools to run a thorough set of tests and reports.</p>
<p>As of this writing <a title="Ubuntu Linux" href="http://www.ubuntu.com/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.ubuntu.com/?referer=');">Ubuntu Linux</a> version 9.10 (Karmic Koala) has just been released. Personally I like Ubuntu for its ease of use, so this howto will focus on that. I assume that the general setup will be slightly different if you use another flavor of Linux, though.</p>
<p>If you don't have a spare computer lying around just yet, install <a title="VMWare Server" href="http://www.vmware.com/products/server/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.vmware.com/products/server/?referer=');">VMWare Server</a>. That will get you going well enough to convince your manager that a few hundred bucks for a medium-spec server will be well invested money.</p>
<p>This step of the tutorial assumes that you're at least somewhat familiar with the Linux command line. If you are not, do yourself a favor and get in touch with one of your system administrators. Make him understand what you want and convince him to divert from the typical company guidelines for server installation. You might want to show him this:</p>
<blockquote><p>This will be a test server. It will not run in production. It will never be accessible by the public. It'll be a proof of concept and will be replaced by a server compliant to all guidelines once this proof of concept is approved by management.</p></blockquote>
<p>For those of you who do this on their own: The above paragraph is for you. All aspects of creating a secure, well administered server with backup are ignored in this tutorial. Do not attempt to run this box online.</p>
<p>One more comment. Even if you're convinced that you'll not be using one of the packages or reports described below, just install them for now. The whole setup is well under 2GB and it works. Removing a package might break things.</p>
<p>This being said, are you ready for the installation?</p>
<h4><span id="more-76"></span>Step one: Set up a LAMP Server.</h4>
<p>Go to the <a title="Ubuntu Linux" href="http://www.ubuntu.com/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.ubuntu.com/?referer=');">Ubuntu Homepage</a> and download the .iso CD image of 9.10 Karmic Koala. I grabbed the 32-bit version but I assume the 64-bit will run just fine. VMWare users: You can directly mount the .iso image as CD in the virtual machine. No need to burn a disc.</p>
<p>Follow the graphical installer, it is pretty straight forward. Write down the user name for the unprivileged user you will be asked to create during the process, we will need it later.</p>
<p>When you reach the package selection, check 'LAMP', 'OpenSSH' and 'Samba', you will need it.</p>
<p>Now go for lunch, the download of the additional packages will take a bit.</p>
<h4>Step two: Basic setup.</h4>
<p>You should set up your OpenSSH public key authorization for root and one unprivileged user, any bash aliases that you like as well as any Samba shares that you require. Since I can't know your requirements, I won't even try to give a one-size-fits-all description. Push your question in the comments below and I will answer asap if I can.</p>
<p>You will want one Samba share pointing to where the apache environments will be:</p>
<pre>vi /etc/samba/smb.conf</pre>
<p>Activate the line reading</p>
<pre>security = user</pre>
<p>Append this section to the end of the file.</p>
<pre>#---- start webserver vhost main directory
comment = webserver main directory
read only = no
create mask = 0664
directory mask = 0775
force group = www-data
#---- end webserver vhost main directory</pre>
<p>After that, restart Samba</p>
<pre>/etc/init.d/samba restart</pre>
<h4>Step three: Install basic packages.</h4>
<p>A few essentials are missing after the initial installation of Ubuntu. For example we need to install quite a few additional PHP packages as well as <a title="Subversion homepage" href="http://subversion.tigris.org/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/subversion.tigris.org/?referer=');">Subversion</a> (my personal favorite in revision control).</p>
<p>Make sure you're logged in as root user.</p>
<pre>apt-get install php5 php5-dev php5-cli php5-curl php5-gd php5-mysql
apt get install php5-sqlite php5-xmlrpc php5-imagick php5-mcrypt
apt-get install php-pear php5-xsl php5-xdebug
apt-get install subversion
apt-get install zip unzip mailutils</pre>
<p>I assume that you might need additional PHP packages. Feel free to add them. However the list above is what we'll need for continuous integration.</p>
<h4>Step four: Install continuous integration software.</h4>
<p>This is where the fun starts. Luckily next to everything we need can be installed thru the handy PEAR installer, so the complexity is down to a minimum.</p>
<pre>pear channel-discover pear.phpunit.de
pear channel-discover pear.phing.info
pecl install xdebug
pear install phpunit/PHPUnit-3.4.2
pear install Image_GraphViz PhpDocumentor
pear install http://pear.phing.info/get/phing-2.4.0RC2.tgz
pear install channel://pear.php.net/VersionControl_SVN-0.3.3
pear install channel://pear.php.net/XML_Serializer-0.20.0
pear install PEAR_PackageFileManager_Plugins PEAR_PackageFileManager</pre>
<p>Please note that there is a death-grip like dependency between PHPUnit and phing. phing before v2.4 does not run with PHPUnit 3.4.x because one class was replaced in the latter. On the other hand, PHPUnit before version 3.4.x is not able to perform screenshots for failing Selenium tests, something that you'll definitely want if you plan to automate your frontend testing as well.</p>
<p>You might want to check the <a title="phing website - A build tool for PHP" href="http://phing.info/trac/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/phing.info/trac/?referer=');">phing website</a> if 2.4.0 final is released by the time you read this. I didn't run into any difficulties with the RC2 of phing though.</p>
<p>Since almost everything is based on PEAR, we need to adapt the include_path directive in the php.ini files:</p>
<p>Do a</p>
<pre>vi /etc/php5/apache2/php.ini</pre>
<p>and a</p>
<pre>vi /etc/php5/cli/php.ini</pre>
<p>and in both files find the line</p>
<pre>include_path = ".:/usr/share/php"</pre>
<p>and remove the comment.</p>
<h4>Step five: Install SeleniumRC.</h4>
<p><a title="Selenium RC homepage" href="http://seleniumhq.org/projects/remote-control/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/seleniumhq.org/projects/remote-control/?referer=');">SeleniumRC</a> or Selenium Remote Control is a solution to automate front end testing without the need for a display. For its installation, follow me:</p>
<pre>apt-get install openjdk-6-jre-headless xvfb lynx firefox imagemagick

wget -O /var/www/seleniumRC.zip http://release.seleniumhq.org/selenium-remote-control/1.0.1/selenium-remote-control-1.0.1-dist.zip
unzip /var/www/seleniumRC.zip -d /var/www/
mv /var/www/selenium-remote-control-1.0.1 /var/www/SeleniumRC
rm /var/www/seleniumRC.zip</pre>
<p>We now have the SeleniumRC server (a java program) installed in /var/www/SeleniumRC. Also, we installed the Xvfb virtual frame buffer X server and Firefox 3.5, the former enabling the latter to run without an attached monitor, mouse or keyboard.</p>
<h4>Step six: Create the 'dev' environment.</h4>
<p>As I described in the <a title="First article on continuous integration for PHP" href="/test-automation/2009/11/howto-setting-continous-integration-php/" target="_self">first article</a>, I typically use three different environments for continuous integration. A 'dev' environment for the developer, an 'int' environment where the continuous integration takes place as well as a third 'stage' environment to show the client the latest working revision.</p>
<p>In order to try out continuous integration we will simply install all three virtual hosts on one and the same machine.</p>
<p>With Ubuntu the default host for apache is in /var/www. While that is nice and well, I thrive for a little more consistency, hence we begin by moving the default host to its new home for its purpose as the 'dev' environment.</p>
<pre>mkdir -p /var/www/vhosts/default/conf
mkdir /var/www/vhosts/default/htdocs
mkdir /var/www/vhosts/default/tests
mkdir /var/www/vhosts/default/buildScripts</pre>
<pre>mv /var/www/index.html /var/www/vhosts/default/htdocs/.

mv /etc/apache2/sites-available/default /var/www/vhosts/default/conf/.
ln -s /var/www/vhosts/default/conf/default /etc/apache2/sites-available/default

mv /etc/apache2/sites-available/default-ssl /var/www/vhosts/default/conf/.
ln -s /var/www/vhosts/default/conf/default-ssl /etc/apache2/sites-available/default-ssl

vi /var/www/vhosts/default/conf/default</pre>
<p>Now change the DocumentRoot directive to</p>
<pre>/var/www/vhosts/default/htdocs</pre>
<p>and also change</p>
<pre>&lt;Directory /var/www&gt;</pre>
<p>to</p>
<pre>&lt;Directory /var/www/vhosts/default/htdocs&gt;</pre>
<h4>Step seven: Create the 'int' and 'stage' environments.</h4>
<p>The setup for both the integration and staging environments is almost identical to the 'dev' setup. We start with 'int':</p>
<pre>mkdir -p /var/www/vhosts/integration/conf
mkdir /var/www/vhosts/integration/htdocs
mkdir /var/www/vhosts/integration/tests
mkdir /var/www/vhosts/integration/buildScripts

cp /var/www/vhosts/default/conf/default /var/www/vhosts/integration/conf/vhost.conf
ln -s /var/www/vhosts/integration/conf/vhost.conf /etc/apache2/sites-available/integration.conf
ln -s /etc/apache2/sites-available/integration.conf /etc/apache2/sites-enabled/</pre>
<pre>vi /var/www/vhosts/integration/conf/vhost.conf</pre>
<p>Now add</p>
<pre>ServerName    integrate.integration.local</pre>
<p>and once more change the DocumentRoot directive, this time to</p>
<pre>/var/www/vhosts/integration/htdocs</pre>
<p>and also change</p>
<pre>&lt;Directory /var/www/vhosts/default/htdocs&gt;</pre>
<p>to</p>
<pre>&lt;Directory /var/www/vhosts/integration/htdocs&gt;</pre>
<p>As said, for the staging environment it is almost the same:</p>
<pre>mkdir -p /var/www/vhosts/demo/conf
mkdir /var/www/vhosts/demo/htdocs
mkdir /var/www/vhosts/demo/tests
mkdir /var/www/vhosts/demo/buildScripts

# create virtual host conf file
cp /var/www/vhosts/default/conf/default /var/www/vhosts/demo/conf/vhost.conf
ln -s /var/www/vhosts/demo/conf/vhost.conf /etc/apache2/sites-available/demo.conf
ln -s /etc/apache2/sites-available/demo.conf /etc/apache2/sites-enabled/</pre>
<pre>vi /var/www/vhosts/demo/conf/vhost.conf</pre>
<p>Now add</p>
<pre>ServerName    demo.integration.local</pre>
<p>and one last time change the DocumentRoot directive, this time to</p>
<pre>/var/www/vhosts/demo/htdocs</pre>
<p>and also change</p>
<pre>&lt;Directory /var/www/vhosts/default/htdocs&gt;</pre>
<p>to</p>
<pre>&lt;Directory /var/www/vhosts/demo/htdocs&gt;</pre>
<h4>Step eight: Setting permissions, restarting Apache<em><br />
</em></h4>
<p>We simply want to correct the file system permissions so that both the unprivileged user and the webserver have write permissions everywhere. You do remember that I said this server will not be secure, right?</p>
<p>Do you remember the user name for the unprivileged user you sat up during the installation procedure? Fill in that user name below</p>
<pre>chown -R YOUR_USERNAME:www-data /var/www
chmod -R g+w /var/www</pre>
<p>We need to restart apache in order to 'activate' the three virtual hosts we just created in step seven.</p>
<pre>/etc/init.d/apache2 restart</pre>
<h4>Last step: Making the host names known.</h4>
<p>You may have wondered about the unusual host names, ending in .local. Well you could name them whatever you want but I prefer .local personally because that makes it absolutely clear that this is a non public machine.</p>
<p>In order to make them accessible you may ask your system administrators to configure your local DNS zone. Or you simply add the host names to the hosts file of your development machine (probably Windows or Mac) and to the Ubuntu server we're currently configuring. For the latter one all you need to do is</p>
<pre>vi /etc/hosts</pre>
<p>and append this section</p>
<pre>127.0.0.1    integration.local
127.0.0.1    integrate.integration.local
127.0.0.1    demo.integration.local</pre>
<p>Note that on your Windows machine you will probably want to do the same, but with the IP address of the virtual machine. Your hosts file for Windows usually sits in c:\WINDOWS\system32\drivers\etc</p>
<h4>Alright, that's it!</h4>
<p>You've just set up the whole continuous integration environment.</p>
<p>Before I let you wander through the (required, really) manuals and user guides of <a title="User Guide for phing - the PHP build tool " href="http://phing.info/docs/guide/stable/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/phing.info/docs/guide/stable/?referer=');">phing</a>, <a title="User Guide for PHPUnit" href="http://www.phpunit.de/manual/3.4/en/index.html" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.phpunit.de/manual/3.4/en/index.html?referer=');">PHPUnit</a>, Selenium ([<a title="The official documentation for SeleniumIDE and SeleniumRC" href="http://seleniumhq.org/docs/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/seleniumhq.org/docs/?referer=');">1</a>], [<a title="PHPUnit manual about usage with SeleniumRC" href="http://www.phpunit.de/manual/3.4/en/selenium.html" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.phpunit.de/manual/3.4/en/selenium.html?referer=');">2</a>]) and what not, bare with me for a few more moments though.</p>
<p>Let us just summarize what we did.</p>
<p>We've set up an Ubuntu Linux server that runs on your computer, right along with whatever operating system you use to see this website.</p>
<p>That server has Apache, PHP, MySQL, Samba and OpenSSH and thus can be considered a full fledged LAMP server. However it is highly insecure.</p>
<p>We installed a PHP build tool (phing), a regression testing tool (PHPUnit),  Xdebug for code coverage. We can generate API docs on the fly (phpDocumentor) and we a graphical environment (Xvfb) and Firefox for frontend tests with Selenium.</p>
<p>All three Apache environments run on the same machine which is different what I mentioned to be my ideal setup in the <a title="First article in my series on setting up continuous integration for PHP" href="http://www.st-webdevelopment.de/test-automation/2009/11/howto-setting-continous-integration-php/" target="_self" onclick="pageTracker._trackPageview('/outgoing/www.st-webdevelopment.de/test-automation/2009/11/howto-setting-continous-integration-php/?referer=');">first article</a> of this series. However, for the purpose of this demo this is perfectly alright. If you want to go into production with continuous integration, simply repeat all the steps above for your two (or three) machines, once for each environment. You can and should leave out the Samba configuration for your integration and staging system however. Oh and get back to your system admin, thank him for his work so far and kindly ask him to secure those boxes!</p>
<p>Okay that concludes the second part in this series. Come back here in a bit to continue with the third part: <a title="Third article in my series on continuous integration for PHP" href="/test-automation/2009/11/howto-continuous-integration-php-pt-3/" target="_self">Automating tests and reports with phing</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.st-webdevelopment.com/test-automation/2009/11/howto-continuous-integration-php-pt-2/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>HOWTO: Continuous Integration for PHP, pt. 1</title>
		<link>http://www.st-webdevelopment.com/test-automation/2009/11/howto-setting-continous-integration-php/</link>
		<comments>http://www.st-webdevelopment.com/test-automation/2009/11/howto-setting-continous-integration-php/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 18:13:31 +0000</pubDate>
		<dc:creator>Dominique</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Test Automation]]></category>
		<category><![CDATA[continuous integration]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[phing]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[phpunit]]></category>
		<category><![CDATA[selenium]]></category>

		<guid isPermaLink="false">http://www.st-webdevelopment.de/?p=58</guid>
		<description><![CDATA[The first in a series of articles on how to set up an continuous integration environment for PHP.]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-59" title="bubbles" src="http://www.st-webdevelopment.de/wp-content/uploads/2009/11/bubbles1.jpg" alt="bubbles" width="190" height="400" />After my <a title="My post on setting up a new VHost" href="http://www.st-webdevelopment.de/test-automation/2009/11/new-vm-first-tests-with-phing/" target="_self" onclick="pageTracker._trackPageview('/outgoing/www.st-webdevelopment.de/test-automation/2009/11/new-vm-first-tests-with-phing/?referer=');">initial post</a> which gave only a rough outline on how to install all the various components for a continuous integration environment for PHP I had to struggle quite a bit to get everything to work. There doesn't seem to be a tutorial or howto online that goes to the level of depth required. Hence I decided to make my own.</p>
<p>This will be a series of several posts where I will try to cover all basic aspects of continuous integration for PHP:</p>
<p>An informational article about what continuous integration is all about.</p>
<p>After that I'll give you a <a title="Second article on continuous integration with PHP: Installing a Linux test server" href="/test-automation/2009/11/howto-continuous-integration-php-pt-2/" target="_self">step-by-step guide</a> on how to set up a continuous integration environment using a virtual environment.</p>
<p>I will provide you with an example build script for <a title="Third article in my series on continuous integration for PHP" href="/test-automation/2009/11/howto-continuous-integration-php-pt-3/" target="_self">automated local tests</a> in the third article.</p>
<p>The fourth article will put all things together and <a title="My fourth article in the series on continuous integration for PHP" href="/test-automation/2009/11/howto-continuous-integration-php-pt-4/" target="_self">establish continuous integration</a>.</p>
<h4>This article will cover the first topic "What is continuous integration all about?".</h4>
<p>Continuous integration is an important aspect in agile development methodologies and test driven development.</p>
<p>The whole idea behind continuous integration is to have a process running in the background that integrates and tests the various pieces of source code that you generated continuously and automatically. In a nutshell, that's it.</p>
<p>Why would we want to automate our testing? Well I believe that is obvious:</p>
<ol>
<li>Testing is hard.</li>
<li>Testing is boring.</li>
<li>Testing is time consuming.</li>
</ol>
<p><span id="more-58"></span>All three aspects - and there might be more - make it impractical to achieve complete test coverage manually even in a medium sized project. It becomes much more feasible to invest the effort of setting up an automated test environment and writing the tests once which from then on will run day after day after day.</p>
<h4>Which components are required for continuous integration with PHP?</h4>
<p>There are a few alternatives to what I'm going to discuss here (I give some of them in parenthesis) but roughly you'll want:</p>
<ul>
<li>Unittest scripts that will cover your regression tests. <a title="PHPUnit Website" href="http://www.phpunit.de" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.phpunit.de?referer=');">PHPUnit</a> is the tool of choice here (<a title="SimpleTest Homepage" href="http://www.simpletest.org/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.simpletest.org/?referer=');">SimpleTest</a> also does a good job)</li>
<li>A build tool such as <a title="phing website - A build tool for PHP" href="http://phing.info/trac/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/phing.info/trac/?referer=');">phing</a>. It will automate the building of your test environment.</li>
<li>For the continuity aspect a cronjob is enough. (<a title="CruiseControl home" href="http://cruisecontrol.sourceforge.net/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/cruisecontrol.sourceforge.net/?referer=');">CruiseControl</a> &amp; <a href="http://phpundercontrol.org/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/phpundercontrol.org/?referer=');">phpUnderControl </a>are much more sophisticated. Check them out if a cronjob is not cutting it for you)</li>
<li>You will need some sort of revision control. My tool of choice is <a title="Subversion homepage" href="http://subversion.tigris.org/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/subversion.tigris.org/?referer=');">Subversion</a>. (<a title="CVS homepage" href="http://www.nongnu.org/cvs/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.nongnu.org/cvs/?referer=');">CVS</a>, and <a title="the Wikipedia on Revision Control" href="http://en.wikipedia.org/wiki/Revision_control" target="_blank" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Revision_control?referer=');">many others</a> are available)</li>
<li>I strongly recommend using your own integration environment over testing on your development machine. <a title="VMWare homepage" href="http://www.vmware.com/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.vmware.com/?referer=');">VMWare </a>is a great free virtualizer.</li>
</ul>
<h4>Is there more that we can do with continuous integration?</h4>
<p>Hell yes! Here are a few examples:</p>
<ul>
<li>Frontend testing (yes, automated) with <a title="Selenium IDE homepage - automated frontend testing for websites" href="http://seleniumhq.org/projects/ide/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/seleniumhq.org/projects/ide/?referer=');">Selenium IDE</a> and <a title="Selenium RC homepage" href="http://seleniumhq.org/projects/remote-control/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/seleniumhq.org/projects/remote-control/?referer=');">Selenium Remote Control</a>. Note that you will also need some sort of graphical environment for that. <a title="Wikipedia on Xvfb, a headless graphical environment." href="http://en.wikipedia.org/wiki/Xvfb" target="_blank" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Xvfb?referer=');">Xvfb </a>is usually good enough.</li>
<li>You could generate your API doc for PHP with <a title="phpDocumentor" href="http://www.phpdoc.org/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.phpdoc.org/?referer=');">phpDocumentor</a>.</li>
<li>You certainly can generate an API doc for <a title="JsDoc Toolkit - API doc for JavaScript" href="http://code.google.com/p/jsdoc-toolkit/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/code.google.com/p/jsdoc-toolkit/?referer=');">JavaScript </a>as well.</li>
<li>You could perform unittests for <a title="JavaScript unittest frameworks" href="http://www.google.com/search?q=javascript+unittest" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?q=javascript+unittest&amp;referer=');">JavaScript </a>or your <a title="QUnit - Unittesting for jQuery" href="http://docs.jquery.com/QUnit" target="_blank" onclick="pageTracker._trackPageview('/outgoing/docs.jquery.com/QUnit?referer=');">jQuery plugins</a>.</li>
<li>and last not least why don't you push everything on a staging system for your client to see when everything goes well?</li>
</ul>
<p>Now that we have that covered...</p>
<h4>How does an environment with continuous integration look like?<br />
How do we have to work in order to get the most out of it?</h4>
<p>As usual, there are many ways to do this. My personal approach consists of two, better three environments:</p>
<p>First, the development machine(s). That is where we develop our code.<br />
Second, the integration machine, where the continuous integration is happening.<br />
Third, optionally a system for staging. This gives you constant feedback from the client.</p>
<p>Overall the workflow looks like this:</p>
<div id="attachment_62" class="wp-caption aligncenter" style="width: 447px"><img class="size-full wp-image-62" title="environment" src="http://www.st-webdevelopment.de/wp-content/uploads/2009/11/environment.png" alt="My continuous integration environment" width="437" height="273" /><p class="wp-caption-text">My continuous integration environment</p></div>
<p>The 'devel' environment is local on the developers' machine. A virtual machine as I pointed out earlier but that is not relevant at this moment. If there is more than one developer, each will have his own 'devel' environment. The development (1) is done locally. All developers commit to and update  from a central Subversion repository (2).</p>
<p>The 'int' (integration) environment usually sits on a different piece of hardware. I prefer the 'int' and the 'stage' system to be on two different virtual hosts on one machine. However your setup might be, on the 'int' environment a cronjob is running continuously and pulls the latest revision of the product out of Subversion (3). If a new revision is found, the integration (4) starts, running all tests, generating all reports, writing API docs and so on.</p>
<p>If an error occurs during the integration test, a mail is being sent to all developers. I've heard of teams who change the color of an ambient orb to red in this case, or switch on a lava lamp. Do as you please. A mail is a good start, however. The team can then utilize all reports on 'int' (available thru the apache virtual host) to inspect the problem and fix it.</p>
<p>Because the integration is continuous, the feedback about a failing test is fast.<strong> </strong></p>
<p>Not much code has to be revised in order to find and fix the bug.</p>
<p>Only when the integration runs without errors, the step (5) starts: Deploying that revision to the 'stage' environment where the client can test it. If you think that might probably not be a good idea in your case / with your client, you might be right. Releasing every other week, at the end of a sprint works just as well. This last step (5) is optional.</p>
<p>That concludes the first part in my series on setting up continuous integration for PHP. Continue with the second part: <a title="Second article on continuous integration with PHP: Installing a Linux test server" href="/test-automation/2009/11/howto-continuous-integration-php-pt-2/" target="_self">A installation howto</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.st-webdevelopment.com/test-automation/2009/11/howto-setting-continous-integration-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>New VM, first tests with Phing</title>
		<link>http://www.st-webdevelopment.com/test-automation/2009/11/new-vm-first-tests-with-phing/</link>
		<comments>http://www.st-webdevelopment.com/test-automation/2009/11/new-vm-first-tests-with-phing/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 19:02:48 +0000</pubDate>
		<dc:creator>Dominique</dc:creator>
				<category><![CDATA[Test Automation]]></category>
		<category><![CDATA[API doc]]></category>
		<category><![CDATA[deployment]]></category>
		<category><![CDATA[software build]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://webserver.local/wordpress/?p=4</guid>
		<description><![CDATA[This is a summary of an experience on how far you can take test automation within a couple of hours.]]></description>
			<content:encoded><![CDATA[<p>I spent some time today to set up a new <a title="VMWare.com" href="http://www.vmware.com/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.vmware.com/?referer=');">Virtual Machine</a>. My current development system is based on <a title="Ubuntu Linux Distribution" href="http://www.ubuntu.com/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.ubuntu.com/?referer=');">Ubuntu</a> <a href="http://releases.ubuntu.com/intrepid/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/releases.ubuntu.com/intrepid/?referer=');">Intrepid</a> and starts acting up. I can't really isolate the issue, some network trouble is there.</p>
<p>Anyways... originally I just wanted to tap a bit into test automation [<a title="Martin Fowler on Continuous Integration" href="http://martinfowler.com/articles/continuousIntegration.html" target="_blank" onclick="pageTracker._trackPageview('/outgoing/martinfowler.com/articles/continuousIntegration.html?referer=');">1</a>, <a title="The Wikipedia on Continuous Integration" href="http://en.wikipedia.org/wiki/Continuous_integration" target="_blank" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Continuous_integration?referer=');">2</a>] but I ended up downloading the 32bit server version of Ubuntu <a title="Ubuntu Karmic Koala 32bit Server Download" href="http://www.ubuntu.com/getubuntu/download-server" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.ubuntu.com/getubuntu/download-server?referer=');">Koala</a>. With my crappy Tata Photon+ it took a while until the CD .iso file was there but after that it went smooth. The installation system is pretty straight forward and did a decent job of detecting my keyboard.</p>
<p>I chose the LAMP, <a title="Open Secure Shell" href="http://www.openssh.com/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.openssh.com/?referer=');">OpenSSH</a>, <a title="Samba CIFS" href="http://www.samba.org/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.samba.org/?referer=');">Samba</a> packages and let it install.</p>
<p>After that it was just a matter of installing a few more php packages, along with <a title="PHP Extension and Application Repository" href="http://pear.php.net" target="_blank" onclick="pageTracker._trackPageview('/outgoing/pear.php.net?referer=');">PEAR</a>. This enabled me to set up everything I needed to get a glimpse of what test automation is all about.</p>
<pre><code># install PHPUnit (make sure you catch the dependencies)
&gt; pear channel-discover pear.phpunit.de
&gt; pear install phpunit/PHPUnit

# install PhpDocumentor
&gt; pear install PhpDocumentor

# install Phing (once more, cover the dependencies)
&gt; pear channel-discover pear.phing.info
&gt; pear install phing/phing
</code><strong><strong> </strong></strong></pre>
<p>In case you're in doubt what all this means:</p>
<p><a title="PHP Unit testing" href="http://www.phpunit.de/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.phpunit.de/?referer=');">PHPUnit </a>is the unittesting tool for PHP, a clone of JUnit basically...<br />
<a title="PHP Documentor" href="http://www.phpdoc.org/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.phpdoc.org/?referer=');">PhpDocumentor</a> generates a Html (.pdf, ...) API Doc out of your source code comments...<br />
and finally <a title="Phing - the PHP build system" href="http://phing.info/trac/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/phing.info/trac/?referer=');">Phing </a>is a build tool written in and for PHP.</p>
<p>The whole setup tool me less than two hours after the .iso file was there, and that includes additional things like setting up a Samba share and configuring two VirtualHosts for <a title="The Apache Webserver" href="http://httpd.apache.org/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/httpd.apache.org/?referer=');">Apache</a>. Really cool and really really smooth.</p>
<p>Now with a short but to-the-point <a title="Continuous Integration with PHP" href="http://www.linux.com/archive/articles/60657" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.linux.com/archive/articles/60657?referer=');">article </a>on <a title="Linux.com" href="http://www.linux.com/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.linux.com/?referer=');">Linux.com</a> I got a test scenario running. What joy! you simply enter 'phing' on the commandline and the tools clear up the build filesystem, fill the build again with the latest version of the software, run PhpDocumentor to generate the up-to-date APIDoc, then run all unittests and in case those succeed they generate a tarball with the whole system.</p>
<p><strong>How cool is that?!</strong> Really impressive. Those who know me also know that it's hard to impress me <img src='http://www.st-webdevelopment.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .<br />
[Update: <a title="Series on continuous integration with PHP" href="/test-automation/2009/11/howto-setting-continous-integration-php/" target="_self">By now there is a much more in depth series of articles online here in my blog</a>]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.st-webdevelopment.com/test-automation/2009/11/new-vm-first-tests-with-phing/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
