title: How to unit test your API?
body: <p>I'm at the point where I need to write unit tests for a REST API written using CakePHP 1.3. The API supports GET, POST and PUT requests for querying and manipulating data.</p>
  
  <p>Is there any established way to test the correct input/output of an API simulating an HTTP request, using <strong>fixtures</strong>? I do not want to run actual POST/PUT requests against the live (dev) database. How can I best mock out the system to use temporary models, yet test the rest of the stack as-is?</p>
  
  <hr>
  
  <p>Testing GET requests is easy enough with <a href="http://book.cakephp.org/view/1210/Testing-controllers" rel="noreferrer">controller tests</a>. However, for data manipulation the API uses HTTP headers quite extensively and also parses raw XML and JSON POST/PUT data. The controller unit test methods only mock POST data by setting <code>$this-&gt;data</code> in the controller, which does not allow me to properly test the API.</p>