From c6affe480ef7577e8b9936940951f6731b88ee65 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Wed, 15 Aug 2007 07:06:17 +0000 Subject: [PATCH] Making the two MySQL tests create an InnoDB database so that we can practice our new transaction test * UnitTest/DatabaseMySQLTest.php: (DatabaseMySQLTest::setUp): Create the test table as InnoDB * UnitTest/DatabaseMySQLiTest.php: (DatabaseMySQLiTest::setUp): ditto * UnitTest/DatabaseTestAbstract.php: (DatabaseTestAbstract::testTransactions): New method --- UnitTest/DatabaseMySQLTest.php | 2 +- UnitTest/DatabaseMySQLiTest.php | 2 +- UnitTest/DatabaseTestAbstract.php | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/UnitTest/DatabaseMySQLTest.php b/UnitTest/DatabaseMySQLTest.php index d3cf1c5..9fe1c5c 100644 --- a/UnitTest/DatabaseMySQLTest.php +++ b/UnitTest/DatabaseMySQLTest.php @@ -18,7 +18,7 @@ class DatabaseMySQLTest extends DatabaseTestAbstract id int auto_increment, textstuff varchar(255), PRIMARY KEY (id) - ) + ) ENGINE=InnoDb "); } diff --git a/UnitTest/DatabaseMySQLiTest.php b/UnitTest/DatabaseMySQLiTest.php index 63e8509..1e803a9 100644 --- a/UnitTest/DatabaseMySQLiTest.php +++ b/UnitTest/DatabaseMySQLiTest.php @@ -18,7 +18,7 @@ class DatabaseMySQLiTest extends DatabaseTestAbstract id int auto_increment, textstuff varchar(255), PRIMARY KEY (id) - ) + ) Engine=InnoDB "); } diff --git a/UnitTest/DatabaseTestAbstract.php b/UnitTest/DatabaseTestAbstract.php index 31f57a9..e5285f0 100644 --- a/UnitTest/DatabaseTestAbstract.php +++ b/UnitTest/DatabaseTestAbstract.php @@ -162,6 +162,26 @@ abstract class DatabaseTestAbstract extends PHPUnit_Framework_TestCase $this->assertEquals('SELECT * FROM foobar', $e->getQuery()); } } + + public function testTransactions() + { + $this->fixture->begin(); + $this->fixture->query("INSERT INTO test (textstuff) VALUES ('foo')"); + $this->fixture->commit(); + + $res = $this->fixture->query("SELECT * FROM test WHERE textstuff = 'foo'"); + $this->assertEquals(1, $this->fixture->numRows($res)); + + $this->fixture->begin(); + $this->fixture->query("UPDATE test SET textstuff = 'abc'"); + $this->fixture->rollback(); + + $res = $this->fixture->query("SELECT * FROM test WHERE textstuff = 'abc'"); + $this->assertEquals(0, $this->fixture->numRows($res)); + + $res = $this->fixture->query("SELECT * FROM test WHERE textstuff = 'foo'"); + $this->assertEquals(1, $this->fixture->numRows($res)); + } } ?> \ No newline at end of file -- 2.43.5