title: Using a CI Server to Unit Test a Web Application plugin
body: <p>I'm using TeamCity 7 as CI Server, and I'd have to test several Web Application plugins, mainly written with PHP. I'm familiar with ANT and *Unit, but I have an issue to solve: to properly test a plugin, my idea would be the following:</p>
  
  <ol>
  <li>Cleanup the testing environment.</li>
  <li>Install a clean copy of the Web Application which will host the plugin.</li>
  <li>Install the plugin.</li>
  <li>Enable the plugin.</li>
  <li>Run the tests.</li>
  </ol>
  
  <p>Obviously, running the tests on an installed environment is the easy part. Most tests are fired by directly calling plugin's classes' methods, yet the framework must be configured, even with minimal settings, to allow calling its bootstrap file and perform due initialization. I tried running the tests in an environment I prepared manually, and they run as expected.</p>
  
  <p>The issue is now automating the installation of the standard Web Application, and, most importantly, its configuration. The basic steps are the following:</p>
  
  <ol>
  <li>Unzip framework somewhere (done).</li>
  <li>Create a Database (done).</li>
  <li>Create a Database User ans assign it propert privileges (done).</li>
  <li>Run Web Application's setup.</li>
  </ol>
  
  <p>The tricky part is that not all Web Application implement a command line interface, such as <em>drush</em> for Drupal, hence I came out with two possible ways to complete the installation:</p>
  
  <p><strong>Simulate manual installation via CURL</strong></p>
  
  <ul>
  <li>Take note of the installation steps and the forms that need to be filled.</li>
  <li>POST data to each of the forms using CURL.</li>
  </ul>
  
  <p>I tried this method, still manually, with acceptable results. The Web Application gets installed as expected, and it can be used.<br>
  However, this requires a Web Server where the application can run. As far as I know, TeamCity Agents work in their own, random named directories and anything "installed" in them cannot be accessed via HTTP requests.</p>
  
  <p><strong>Backup/Restore</strong>  </p>
  
  <ul>
  <li>Manually pre-install a Web Application and configure its basic settings.</li>
  <li>Zip the Application's directory and a backup of its database.</li>
  <li>Before running the tests, unzip the directory in Agent's working directory.</li>
  <li>Restore the backed-up database. The application will now be "configured".</li>
  </ul>
  
  <p>This method is a bit "rough", but it doesn't require a Web Server to be running. Although the Web Application won't be able to server HTTP requests, that doesn't necessarily matter, as the tests will be run against plugin's classes.</p>
  
  <p>This method has two major drawbacks, though:</p>
  
  <ul>
  <li>Tests involving interaction with the Web Application (e.g. hooks, event handlers, and so on) can't be run.</li>
  <li>Since the Web Application and its database are pre-configured, their parameters will be the same at every run. Therefore, it wouldn't be possible to run two Agents at the same time, for example to test two different plugins.</li>
  </ul>
  
  <p>I'm now wondering if there's a better solution, as both the above look less than optimal to me.</p>
  
  <p>Please note that, although I'm using TeamCity, the CI Server itself should not be a big deal, as I'm running everything with ANT. Therefore, any suggestion, even related to another CI Serverm, will be welcome (I know Hudson, CruiseControl and BuildMaster, I can adapt a concept easily). Thanks.</p>