开发者

Mysql SAVEPOINT in PHPUnit Tests

开发者 https://www.devze.com 2023-03-05 21:09 出处:网络
I\'m having a problem when running my PHPUnit test of creating a new profile, my code doesnt allow duplicate of profile_name and so i have to change it manually everytime i run a test. I actually thou

I'm having a problem when running my PHPUnit test of creating a new profile, my code doesnt allow duplicate of profile_name and so i have to change it manually everytime i run a test. I actually thought of creating a SAVEPOINT before my tests runs and Then ROLLBACK at the end of the test..

My code for setting up the code is:

require_once "PHPUnit/Extensions/Database/TestCase.php"

protected function getDatabaseTester()
{
  $pdo = new PDO('mysql:host=localhost;dbname=test', 'root', 'password');
  $conn = new PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection($pdo, 'test');
}

public function testMyTestCase()
{
  开发者_StackOverflow社区$query = mysql_query(SAVEPOINT last_record);
  *my testing methods thats works fine*
  $query = mysql_query(ROLLBACK last_record);
}

What can i be doing wrong because it doesnt work at all..

Thanks D~~~


you could provide more information with :

 echo mysql_errno() . ": " . mysql_error(). "\n";
 $query = mysql_query("ROLLBACK TO SAVEPOINT last_record");

 

0

精彩评论

暂无评论...
验证码 换一张
取 消