summaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
authorxue <>2006-11-24 19:15:26 +0000
committerxue <>2006-11-24 19:15:26 +0000
commit7280a2301a3d3dd251d8302c3f7999fa09780d42 (patch)
tree4436f61f268a79271ccf7c01fdab7a5be5c50106 /tests/unit
parent88a073ccbb0026e52d2f83aeeaab4bd9591ef3ab (diff)
bug fixes of data layer.
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/Data/TDbCommandTest.php49
-rw-r--r--tests/unit/Data/TDbConnectionTest.php11
2 files changed, 55 insertions, 5 deletions
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()