title: Phpunit testing with database
body: <p>I am trying to focus a bit on unit testing using PHPunit.</p>
  <p>I have found a very good tutorial over here <a href="http://blog.nickbelhomme.com/php/phpunit-training-course-for-free_282" rel="noreferrer">http://blog.nickbelhomme.com/php/phpunit-training-course-for-free_282</a></p>
  <p>But there is something I'm missing and don't yet understand how to do.</p>
  <p>I have a user module which maintains all information about users. And there is a function save which saves the user in the database. So I have a testFunction</p>
  <pre><code>public function testCanCreateUser()
  {
      $userData = array(
          'userName'  =&gt;  'User1',
          'firstName' =&gt;  'Joey',
          'lastName'  =&gt;  'Hendricks',
          'email'     =&gt;  'Joey@hendricks.com',
          'password'  =&gt;  'f$tfe8F'
      
      ); 
      $user = new Model_User($userData);
      $user-&gt;save();
       
  }
  </code></pre>
  <p>The first time when I will run my test this will work. Since the database is empty. But When I run my tests for the second time it won't work since my system doesn't allow the same user twice in the db. So In order to do this I have to recreate my testdatabase every time before I run my tests. What is the best way to do this?</p>
  <p>Or is this problem to be solved on a different way?</p>