views:

105

answers:

3

Hi,

I am a trying to apply Test Driven Development to producing a web page and am having trouble using my database. I am developing using Cake 1.1, PHP5 and SimpleTest to unit test.

My problem is that I have a test that:

  1. Inserts a row using a direct SQL statement
  2. Tests if that row was inserted (by using a function in my main program.)
  3. Deletes the row that was inserted.

Both steps 1 and 3 work fine but step 2 fails.

It's important to realize that if I run the test without deleting the row (I commented that out) and then ran the test again but first eliminating step 1 (once again simply commenting that line) and the test passed without a problem.

I also tried running the SQL statements directly (one after another in the editor) in PHPMyAdmin and they work perfectly.

Any ideas?

+3  A: 

Are all steps executed in the same transaction?

When not, step 2 isn't able to see the result of step 1 until step 1 commits.

David Baakman
They are actually separated SQL statements... I don't think they are the same transaction although they are inside the same PHP function.
Juan Besa
+1  A: 

It does sound like your insert is happening inside a transaction that has not yet been committed when you attempt the test.

Can you give some sample code?

johnc
A: 

Are you sure you are committing the transaction in step 1?

Adam Goode