title: Testing an add method with cakephp and phpunit
body: <p>I'm testing an application made with cake and I found a problem when testing an add method. The problem in fact is that whenever I want to test saving data on the DB, after making a sample data to send with the request, I found out that that data is saved on the DB but with just the id attribute set. The other fields are null. </p>
  
  <p>Here's the method I want to test:</p>
  
  <pre><code>public function admin_add() {
      if ($this-&gt;request-&gt;is('post')) {
          debug($this-&gt;request-&gt;data);
          $this-&gt;Item-&gt;create();
          if ($this-&gt;Item-&gt;save($this-&gt;request-&gt;data)) {
              $this-&gt;Session-&gt;setFlash(__('The item has been saved'));
              //$this-&gt;redirect(array('action' =&gt; 'index'));
          } else {
              $this-&gt;Session-&gt;setFlash(__('The item could not be saved. Please, try again.'));
          }
      }
      $products = $this-&gt;Item-&gt;Product-&gt;find('list');
      $attributes = $this-&gt;Item-&gt;Attribute-&gt;find('list');
      $this-&gt;set(compact('products', 'attributes'));
  }
  </code></pre>
  
  <p>And here's my test:</p>
  
  <pre><code>public function testAdmin_add(){
  
   $this-&gt;Items-&gt;request-&gt;params['action'] = 'admin_add';
   $this-&gt;Items-&gt;request-&gt;params['url']['url'] = 'admin/items/add';
   $data = array(
    'Item' =&gt; array(
      'product_id' =&gt; 1,
      'attribute_id' =&gt; 9,
      'title' =&gt; 'test_item',
      'code' =&gt; 1,
      'in_stock' =&gt; 1,
      'batched_stock'=&gt; 1,
      'allocated' =&gt; 0,
    ),
   );
  
      $this-&gt;Collection = $this-&gt;getMock('ComponentCollection');
    $this-&gt;Items-&gt;Session = $this-&gt;getMock('SessionComponent', array('setFlash'), array($this-&gt;Collection));
  
    $this-&gt;Items-&gt;Session-&gt;expects($this-&gt;once())
          -&gt;method('setFlash')
          -&gt;with(__d('items', 'Se ha guardado el item'));
  
  
   $this-&gt;__setPost($data);
  
   $this-&gt;Items-&gt;admin_add();
  
  }
  </code></pre>
  
  <p>Notice that if I run this test I'll have an extra field on the db, and because table's id is auto-increment I cant get the id back to delete that entry.<br>
  Now the question is: is there any way I can test DB saving without actually save data on it?</p>
  
  <p>Thanks!</p>