Query/tests/databases/mysql.php

89 lines
1.7 KiB
PHP
Raw Normal View History

2012-03-15 09:25:18 -04:00
<?php
/**
* Query
*
* Free Query Builder / Database Abstraction Layer
*
* @author Timothy J. Warren
* @copyright Copyright (c) 2012
* @link https://github.com/aviat4ion/Query
* @license http://philsturgeon.co.uk/code/dbad-license
*/
// --------------------------------------------------------------------------
/**
* MySQLTest class.
*
* @extends UnitTestCase
*/
2012-03-19 13:38:49 -04:00
class MySQLTest extends DBTest {
2012-03-15 15:46:04 -04:00
function setUp()
{
// Attempt to connect, if there is a test config file
if (is_file("../test_config.json"))
2012-03-15 15:46:04 -04:00
{
$params = json_decode(file_get_contents("../test_config.json"));
$params = $params->mysql;
$this->db = new MySQL("host={$params->host};port={$params->port};dbname={$params->database}", $params->user, $params->pass);
}
2012-03-22 16:26:17 -04:00
elseif ( ! empty($_ENV['CI']))
2012-03-22 15:59:03 -04:00
{
2012-03-22 16:12:54 -04:00
$this->db = new MySQL('host=127.0.0.1;port=3306;dbname=test', 'root');
2012-03-22 15:59:03 -04:00
}
2012-03-15 15:46:04 -04:00
}
2012-03-15 09:25:18 -04:00
function TestExists()
{
$this->assertTrue(in_array('mysql', pdo_drivers()));
}
2012-03-15 15:46:04 -04:00
function TestConnection()
{
if (empty($this->db)) return;
$this->assertIsA($this->db, 'MySQL');
}
function TestCreateTable()
{
if (empty($this->db)) return;
//Attempt to create the table
$sql = $this->db->sql->create_table('create_test',
array(
2012-03-15 16:12:20 -04:00
'id' => 'int(10)',
2012-03-15 15:46:04 -04:00
'key' => 'TEXT',
'val' => 'TEXT',
),
array(
'id' => 'PRIMARY KEY'
)
);
2012-03-15 16:12:20 -04:00
2012-03-15 15:46:04 -04:00
$this->db->query($sql);
//Attempt to create the table
$sql = $this->db->sql->create_table('create_join',
array(
2012-03-15 16:12:20 -04:00
'id' => 'int(10)',
2012-03-15 15:46:04 -04:00
'key' => 'TEXT',
'val' => 'TEXT',
),
array(
'id' => 'PRIMARY KEY'
)
);
$this->db->query($sql);
//Check
$dbs = $this->db->get_tables();
2012-03-15 16:12:20 -04:00
$this->assertTrue(in_array('create_test', $dbs));
2012-03-15 15:46:04 -04:00
}
2012-03-15 09:25:18 -04:00
}