Merge branch 'master' of github.com:yiisoft/yii2 into 8670-multi-data-session

This commit is contained in:
Klimov Paul
2015-06-09 12:58:17 +03:00
47 changed files with 811 additions and 115 deletions

View File

@@ -6,6 +6,7 @@ use yii\caching\FileCache;
use yii\db\Connection;
use yii\db\DataReader;
use yii\db\Expression;
use yii\db\Schema;
/**
* @group db
@@ -310,6 +311,40 @@ SQL;
], $record);
}
public function testCreateTable()
{
$db = $this->getConnection();
$db->createCommand("DROP TABLE IF EXISTS testCreateTable;")->execute();
$db->createCommand()->createTable('testCreateTable', ['id' => Schema::TYPE_PK, 'bar' => Schema::TYPE_INTEGER])->execute();
$db->createCommand()->insert('testCreateTable', ['bar' => 1])->execute();
$records = $db->createCommand('SELECT [[id]], [[bar]] FROM {{testCreateTable}};')->queryAll();
$this->assertEquals([
['id' => 1, 'bar' => 1],
], $records);
}
public function testAlterTable()
{
if ($this->driverName === 'sqlite'){
$this->markTestSkipped('Sqlite does not support alterTable');
}
$db = $this->getConnection();
$db->createCommand("DROP TABLE IF EXISTS testAlterTable;")->execute();
$db->createCommand()->createTable('testAlterTable', ['id' => Schema::TYPE_PK, 'bar' => Schema::TYPE_INTEGER])->execute();
$db->createCommand()->insert('testAlterTable', ['bar' => 1])->execute();
$db->createCommand()->alterColumn('testAlterTable', 'bar', Schema::TYPE_STRING)->execute();
$db->createCommand()->insert('testAlterTable', ['bar' => 'hello'])->execute();
$records = $db->createCommand('SELECT [[id]], [[bar]] FROM {{testAlterTable}};')->queryAll();
$this->assertEquals([
['id' => 1, 'bar' => 1],
['id' => 2, 'bar' => 'hello'],
], $records);
}
/*
@@ -321,10 +356,6 @@ SQL;
{
}
public function testCreateTable()
{
}
public function testRenameTable()
{
}
@@ -349,10 +380,6 @@ SQL;
{
}
public function testAlterColumn()
{
}
public function testAddForeignKey()
{
}
@@ -509,4 +536,23 @@ SQL;
$command = $db->createCommand($sql, $params);
$this->assertEquals($expectedRawSql, $command->getRawSql());
}
public function testAutoRefreshTableSchema()
{
$db = $this->getConnection(false);
$tableName = 'test';
$db->createCommand()->createTable($tableName, [
'id' => 'pk',
'name' => 'string',
])->execute();
$initialSchema = $db->getSchema()->getTableSchema($tableName);
$db->createCommand()->addColumn($tableName, 'value', 'integer')->execute();
$newSchema = $db->getSchema()->getTableSchema($tableName);
$this->assertNotEquals($initialSchema, $newSchema);
$db->createCommand()->dropTable($tableName)->execute();
$this->assertNull($db->getSchema()->getTableSchema($tableName));
}
}

View File

@@ -67,6 +67,23 @@ class SchemaTest extends DatabaseTestCase
$this->assertEquals($noCacheTable, $cachedTable);
}
/**
* @depends testSchemaCache
*/
public function testRefreshTableSchema()
{
/* @var $schema Schema */
$schema = $this->getConnection()->schema;
$schema->db->enableSchemaCache = true;
$schema->db->schemaCache = new FileCache();
$noCacheTable = $schema->getTableSchema('type', true);
$schema->refreshTableSchema('type');
$refreshedTable = $schema->getTableSchema('type', false);
$this->assertFalse($noCacheTable === $refreshedTable);
}
public function testCompositeFk()
{
/* @var $schema Schema */