2005-05-17 20:55:27 +00:00
|
|
|
<?php
|
|
|
|
|
2005-05-21 22:40:51 +00:00
|
|
|
uses ('test', 'dbo_factory');
|
2005-05-17 20:55:27 +00:00
|
|
|
|
|
|
|
class DboTest extends TestCase {
|
|
|
|
var $abc;
|
|
|
|
|
|
|
|
// constructor of the test suite
|
|
|
|
function DboTest ($name) {
|
|
|
|
$this->TestCase($name);
|
|
|
|
}
|
|
|
|
|
|
|
|
// called before the test functions will be executed
|
|
|
|
// this function is defined in PHPUnit_TestCase and overwritten
|
|
|
|
// here
|
|
|
|
function setUp() {
|
2005-05-21 22:40:51 +00:00
|
|
|
$this->abc = DboFactory::make('test');
|
2005-05-17 20:55:27 +00:00
|
|
|
$this->createTemporaryTable();
|
|
|
|
}
|
|
|
|
|
|
|
|
// called after the test functions are executed
|
|
|
|
// this function is defined in PHPUnit_TestCase and overwritten
|
|
|
|
// here
|
|
|
|
function tearDown() {
|
2005-05-22 23:24:09 +00:00
|
|
|
if (!$this->abc) return false;
|
|
|
|
|
2005-05-17 20:55:27 +00:00
|
|
|
$this->dropTemporaryTable();
|
|
|
|
}
|
|
|
|
|
|
|
|
function createTemporaryTable () {
|
2005-05-22 23:24:09 +00:00
|
|
|
if (!$this->abc) return false;
|
|
|
|
|
2005-05-17 20:55:27 +00:00
|
|
|
if ($this->abc->config['driver'] == 'postgres')
|
|
|
|
$sql = 'CREATE TABLE __test (id serial NOT NULL, body CHARACTER VARYING(255))';
|
|
|
|
else
|
|
|
|
$sql = 'CREATE TABLE __test (id INT UNSIGNED PRIMARY KEY, body VARCHAR(255))';
|
|
|
|
|
|
|
|
return $this->abc->query($sql);
|
|
|
|
}
|
|
|
|
|
|
|
|
function dropTemporaryTable () {
|
2005-05-22 23:24:09 +00:00
|
|
|
if (!$this->abc) return false;
|
|
|
|
|
2005-05-17 20:55:27 +00:00
|
|
|
return $this->abc->query("DROP TABLE __test");
|
|
|
|
}
|
|
|
|
|
|
|
|
function testHasImplementation () {
|
2005-05-22 23:24:09 +00:00
|
|
|
if (!$this->abc) return false;
|
|
|
|
|
2005-05-17 20:55:27 +00:00
|
|
|
$functions = array(
|
|
|
|
'connect',
|
|
|
|
'disconnect',
|
|
|
|
'execute',
|
|
|
|
'fetchRow',
|
|
|
|
'tables',
|
|
|
|
'fields',
|
|
|
|
'prepare',
|
|
|
|
'lastError',
|
|
|
|
'lastAffected',
|
|
|
|
'lastNumRows',
|
|
|
|
'lastInsertId'
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($functions as $function) {
|
|
|
|
$this->assertTrue(method_exists($this->abc, $function));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function testConnectivity () {
|
2005-05-22 23:24:09 +00:00
|
|
|
if (!$this->abc) return false;
|
|
|
|
|
2005-05-17 20:55:27 +00:00
|
|
|
$this->assertTrue($this->abc->connected);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testFields () {
|
2005-05-22 23:24:09 +00:00
|
|
|
if (!$this->abc) return false;
|
|
|
|
|
2005-05-17 20:55:27 +00:00
|
|
|
$fields = $this->abc->fields('__test');
|
|
|
|
$this->assertEquals(count($fields), 2, 'equals');
|
|
|
|
}
|
|
|
|
|
|
|
|
function testTables () {
|
2005-05-22 23:24:09 +00:00
|
|
|
if (!$this->abc) return false;
|
|
|
|
|
2005-05-17 20:55:27 +00:00
|
|
|
$this->assertTrue(in_array('__test', $this->abc->tables()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|