mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-02-12 06:56:24 +00:00
![brego](/assets/img/avatar_default.png)
git-svn-id: https://svn.cakephp.org/repo/trunk/cake@275 3807eeeb-6ff5-0310-8944-8be069107fe0
101 lines
No EOL
1.8 KiB
PHP
101 lines
No EOL
1.8 KiB
PHP
<?php
|
|
|
|
uses('dbo_factory');
|
|
|
|
class DboTest extends UnitTestCase
|
|
{
|
|
var $dbo;
|
|
|
|
// constructor of the test suite
|
|
function DboTest()
|
|
{
|
|
$this->UnitTestCase('DBO test');
|
|
}
|
|
|
|
// called before the test functions will be executed
|
|
// this function is defined in PHPUnit_TestCase and overwritten
|
|
// here
|
|
function setUp()
|
|
{
|
|
$this->dbo = DBO::getInstance('test');
|
|
|
|
$this->createTemporaryTable();
|
|
}
|
|
|
|
// called after the test functions are executed
|
|
// this function is defined in PHPUnit_TestCase and overwritten
|
|
// here
|
|
function tearDown()
|
|
{
|
|
if(!$this->dbo) return false;
|
|
|
|
$this->dropTemporaryTable();
|
|
}
|
|
|
|
function createTemporaryTable()
|
|
{
|
|
if(!$this->dbo) return false;
|
|
|
|
if($this->dbo->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->dbo->query($sql);
|
|
}
|
|
|
|
function dropTemporaryTable()
|
|
{
|
|
if(!$this->dbo) return false;
|
|
|
|
return $this->dbo->query("DROP TABLE __test");
|
|
}
|
|
|
|
function testHasImplementation()
|
|
{
|
|
if(!$this->dbo) return false;
|
|
|
|
$functions = array(
|
|
'connect',
|
|
'disconnect',
|
|
'execute',
|
|
'fetchRow',
|
|
'tables',
|
|
'fields',
|
|
'prepare',
|
|
'lastError',
|
|
'lastAffected',
|
|
'lastNumRows',
|
|
'lastInsertId'
|
|
);
|
|
|
|
foreach($functions as $function)
|
|
{
|
|
$this->assertTrue(method_exists($this->dbo, $function));
|
|
}
|
|
}
|
|
|
|
function testConnectivity()
|
|
{
|
|
if(!$this->dbo) return false;
|
|
|
|
$this->assertTrue($this->dbo->connected);
|
|
}
|
|
|
|
function testFields()
|
|
{
|
|
if(!$this->dbo) return false;
|
|
|
|
$fields = $this->dbo->fields('__test');
|
|
$this->assertEqual(count($fields), 2, 'equals');
|
|
}
|
|
|
|
function testTables()
|
|
{
|
|
if(!$this->dbo) return false;
|
|
|
|
$this->assertTrue(in_array('__test', $this->dbo->tables()));
|
|
}
|
|
}
|
|
|
|
?>
|