From 7280a2301a3d3dd251d8302c3f7999fa09780d42 Mon Sep 17 00:00:00 2001 From: xue <> Date: Fri, 24 Nov 2006 19:15:26 +0000 Subject: bug fixes of data layer. --- tests/unit/Data/TDbCommandTest.php | 49 +++++++++++++++++++++++++++++++---- tests/unit/Data/TDbConnectionTest.php | 11 ++++++++ 2 files changed, 55 insertions(+), 5 deletions(-) (limited to 'tests/unit/Data') diff --git a/tests/unit/Data/TDbCommandTest.php b/tests/unit/Data/TDbCommandTest.php index f0c02f75..ab94cb3f 100644 --- a/tests/unit/Data/TDbCommandTest.php +++ b/tests/unit/Data/TDbCommandTest.php @@ -19,7 +19,8 @@ class TDbCommandTest extends PHPUnit2_Framework_TestCase $this->_connection=new TDbConnection('sqlite:'.TEST_DB_FILE); $this->_connection->Active=true; $this->_connection->createCommand('CREATE TABLE foo (id INTEGER NOT NULL PRIMARY KEY, name VARCHAR(8))')->execute(); - $this->_connection->createCommand('INSERT TABLE foo (name) VALUES (\'my name\')')->execute; + $this->_connection->createCommand('INSERT INTO foo (name) VALUES (\'my name\')')->execute(); + $this->_connection->createCommand('INSERT INTO foo (name) VALUES (\'my name 2\')')->execute(); } public function tearDown() @@ -36,16 +37,54 @@ class TDbCommandTest extends PHPUnit2_Framework_TestCase public function testSetText() { - $sql='SELECT * FROM foo'; - $newSql='SELECT id FROM foo'; + $sql='SELECT name FROM foo'; $command=$this->_connection->createCommand($sql); - $command->query()->read(); + $row=$command->query()->read(); + $this->assertEquals($row['name'],'my name'); + + $newSql='SELECT id FROM foo'; $command->Text=$newSql; $this->assertEquals($command->Text,$newSql); $row=$command->query()->read(); - $this->assertEquals($row['id'],1); + + $this->assertEquals($row['id'],'1'); } + public function testConnection() + { + $sql='SELECT name FROM foo'; + $command=$this->_connection->createCommand($sql); + $this->assertTrue($command->Connection instanceof TDbConnection); + } + + public function testPrepare() + { + $sql='SELECT name FROM foo'; + $command=$this->_connection->createCommand($sql); + $this->assertTrue($command->PdoStatement===null); + $command->prepare(); + $this->assertTrue($command->PdoStatement instanceof PDOStatement); + + try + { + $command->Text='Bad SQL'; + $command->prepare(); + $this->fail('Expected exception is not raised'); + } + catch(TDbException $e) + { + } + } + + public function testCancel() + { + $sql='SELECT name FROM foo'; + $command=$this->_connection->createCommand($sql); + $command->prepare(); + $this->assertTrue($command->PdoStatement instanceof PDOStatement); + $command->cancel(); + $this->assertEquals($command->PdoStatement,null); + } /* public function testActive() { diff --git a/tests/unit/Data/TDbConnectionTest.php b/tests/unit/Data/TDbConnectionTest.php index 21d6730b..6c1e71aa 100644 --- a/tests/unit/Data/TDbConnectionTest.php +++ b/tests/unit/Data/TDbConnectionTest.php @@ -38,12 +38,23 @@ class TDbConnectionTest extends PHPUnit2_Framework_TestCase $this->_connection2->Active=true; $this->assertTrue($this->_connection2->Active); $pdo=$this->_connection2->PdoInstance; + $this->assertTrue($pdo instanceof PDO); // test setting Active repeatedly doesn't re-connect DB $this->_connection2->Active=true; $this->assertTrue($pdo===$this->_connection2->PdoInstance); $this->_connection2->Active=false; $this->assertFalse($this->_connection2->Active); + + try + { + $connection=new TDbConnection('unknown:'.TEST_DB_FILE); + $connection->Active=true; + $this->fail('Expected exception is not raised'); + } + catch(TDbException $e) + { + } } public function testCreateCommand() -- cgit v1.2.3