Commit e6a9e645 by Qiang Xue

finished Connection.

parent f082c0eb
......@@ -349,17 +349,13 @@ class YiiBase
$object = new $class;
}
if ($object instanceof Initable) {
foreach ($config as $name => $value) {
$object->$name = $value;
}
if ($object instanceof \yii\base\Initable) {
$object->init();
}
else {
foreach ($config as $name => $value) {
$object->$name = $value;
}
}
return $object;
}
......
......@@ -28,18 +28,6 @@ abstract class ApplicationComponent extends Component implements Initable
public $behaviors = array();
/**
* Pre-initializes this component.
* This method is required by the [[Initable]] interface. It is invoked by
* [[\Yii::createComponent]] after its creates the new component instance but
* BEFORE the component properties are initialized.
*
* You may override this method to do work such as setting property default values.
*/
public function preinit()
{
}
/**
* Initializes the application component.
* This method is invoked after the component is created and its property values are
* initialized. The default implementation will call [[Component::attachBehaviors]]
......
......@@ -143,7 +143,7 @@ class Schema extends \yii\db\dao\Schema
foreach ($matches as $match) {
$fks = array_map('trim', explode(',', str_replace('`', '', $match[1])));
$pks = array_map('trim', explode(',', str_replace('`', '', $match[3])));
$constraint = array(str_replace('`', '', $match[2])),
$constraint = array(str_replace('`', '', $match[2]));
foreach ($fks as $k => $name) {
$constraint[$name] = $pks[$k];
}
......
......@@ -7,13 +7,14 @@ class ConnectionTest extends TestCase
function setUp()
{
if(!extension_loaded('pdo') || !extension_loaded('pdo_mysql'))
$this->markTestSkipped('PDO and MySQL extensions are required.');
$this->markTestSkipped('pdo and pdo_mysql extensions are required.');
}
function testConstruct()
{
$connection = $this->createConnection();
$params = $this->getParam('mysql');
$connection = new Connection($params['dsn'], $params['username'], $params['password']);
$this->assertEquals($params['dsn'], $connection->dsn);
$this->assertEquals($params['username'], $connection->username);
$this->assertEquals($params['password'], $connection->password);
......@@ -21,8 +22,8 @@ class ConnectionTest extends TestCase
function testOpenClose()
{
$params = $this->getParam('mysql');
$connection = new Connection($params['dsn'], $params['username'], $params['password']);
$connection = $this->createConnection();
$this->assertFalse($connection->active);
$this->assertEquals(null, $connection->pdo);
......@@ -39,6 +40,58 @@ class ConnectionTest extends TestCase
$connection->open();
}
function testGetDriverName()
{
$connection = $this->createConnection();
$this->assertEquals('mysql', $connection->driverName);
$this->assertFalse($connection->active);
}
function testQuoteValue()
{
$connection = $this->createConnection();
$this->assertEquals(123, $connection->quoteValue(123));
$this->assertEquals("'string'", $connection->quoteValue('string'));
$this->assertEquals("'It\'s interesting'", $connection->quoteValue("It's interesting"));
}
function testQuoteTableName()
{
$connection = $this->createConnection();
$this->assertEquals('`table`', $connection->quoteTableName('table'));
$this->assertEquals('`table`', $connection->quoteTableName('`table`'));
$this->assertEquals('`schema`.`table`', $connection->quoteTableName('schema.table'));
}
function testQuoteColumnName()
{
$connection = $this->createConnection();
$this->assertEquals('`column`', $connection->quoteColumnName('column'));
$this->assertEquals('`column`', $connection->quoteColumnName('`column`'));
$this->assertEquals('`table`.`column`', $connection->quoteColumnName('table.column'));
}
function testGetPdoType()
{
$connection = $this->createConnection();
$this->assertEquals(\PDO::PARAM_BOOL, $connection->getPdoType('boolean'));
$this->assertEquals(\PDO::PARAM_INT, $connection->getPdoType('integer'));
$this->assertEquals(\PDO::PARAM_STR, $connection->getPdoType('string'));
$this->assertEquals(\PDO::PARAM_NULL, $connection->getPdoType('NULL'));
}
function testAttribute()
{
}
function createConnection()
{
$params = $this->getParam('mysql');
return new Connection($params['dsn'], $params['username'], $params['password']);
}
/*
function testCreateCommand()
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment