Skip to content
This repository has been archived by the owner on Dec 3, 2018. It is now read-only.

Commit

Permalink
installation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Bizley committed Jan 29, 2017
1 parent e9c3753 commit fe77e58
Showing 1 changed file with 215 additions and 13 deletions.
228 changes: 215 additions & 13 deletions tests/unit/InstallationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,113 @@ class InstallationTest extends Unit
public $tester;

public $steps = [
'createTest' => [
'createTableTest' => [
[
'table' => 'log',
'table' => 'test',
'call' => 'createTable',
'data' => [
'schema' => [
'id' => Schema::TYPE_BIGPK,
'id' => Schema::TYPE_PK,
'level' => Schema::TYPE_INTEGER,
'category' => Schema::TYPE_STRING,
'log_time' => Schema::TYPE_DOUBLE,
'ip' => Schema::TYPE_STRING . '(20)',
'message' => Schema::TYPE_TEXT,
'model' => Schema::TYPE_INTEGER,
'user' => Schema::TYPE_INTEGER,
'key_f' => Schema::TYPE_INTEGER,
],
],
]
]
],
'addColumnTest' => [
[
'table' => 'test',
'call' => 'addColumn',
'data' => [
'col' => 'added',
'type' => Schema::TYPE_INTEGER,
],
]
],
'dropColumnTest' => [
[
'table' => 'test',
'call' => 'dropColumn',
'data' => [
'col' => 'added',
],
]
],
'addIndexTest' => [
[
'table' => 'test',
'call' => 'addIndex',
'data' => [
'name' => 'sort',
'cols' => ['level'],
],
]
],
'dropIndexTest' => [
[
'table' => 'test',
'call' => 'dropIndex',
'data' => [
'name' => 'sort',
],
]
],
'addForeignTest' => [
[
'table' => 'test',
'call' => 'addForeign',
'data' => [
'key' => 'key_f',
'ref' => 'test_foreign',
'col' => 'id',
'delete' => 'CASCADE',
'update' => 'CASCADE',
],
]
],
'dropForeignTest' => [
[
'table' => 'test',
'call' => 'dropForeign',
'data' => [
'name' => 'key_f',
],
]
],
'alterColumnTest' => [
[
'table' => 'test',
'call' => 'alterColumn',
'data' => [
'col' => 'message',
'type' => Schema::TYPE_STRING,
],
]
],
'renameColumnTest' => [
[
'table' => 'test',
'call' => 'renameColumn',
'data' => [
'col' => 'message',
'name' => 'messageRenamed',
],
]
],
];

protected function _before()
{
parent::_before();
\Yii::$app->session->remove(Installation::SESSION_KEY);
}

public static function tearDownAfterClass()
{
$db = (new Installation)->db;
$tables = ['log'];
$tables = ['test', 'test_foreign'];
foreach ($tables as $table) {
if ($db->schema->getTableSchema("{{%podium_$table}}", true) !== null) {
$db->createCommand()->dropTable("{{%podium_$table}}")->execute();
Expand All @@ -49,22 +132,141 @@ public static function tearDownAfterClass()

public function testCreateTable()
{
\Yii::$app->session->remove(Installation::SESSION_KEY);
$install = Stub::construct(Installation::className(), [], ['_steps' => $this->steps['createTest']]);
$install = Stub::construct(Installation::className(), [], ['_steps' => $this->steps['createTableTest']]);
$result = $install->nextStep();
expect($result['drop'])->equals(false);
expect($result['type'])->equals(Installation::TYPE_SUCCESS);
expect($result['result'])->equals('Table podium_test has been created');
expect($result['table'])->equals('podium_test');
expect_that($install->db->schema->getTableSchema("{{%podium_test}}", true));
}

/**
* @depends testCreateTable
*/
public function testAddColumn()
{
$install = Stub::construct(Installation::className(), [], ['_steps' => $this->steps['addColumnTest']]);
$result = $install->nextStep();
expect($result['drop'])->equals(false);
expect($result['type'])->equals(Installation::TYPE_SUCCESS);
expect($result['result'])->equals('Table column added has been added');
expect($result['table'])->equals('podium_test');
expect($install->db->schema->getTableSchema("{{%podium_test}}", true)->columns)->hasKey('added');
}

/**
* @depends testAddColumn
*/
public function testDropColumn()
{
$install = Stub::construct(Installation::className(), [], ['_steps' => $this->steps['dropColumnTest']]);
$result = $install->nextStep();
expect($result['drop'])->equals(false);
expect($result['type'])->equals(Installation::TYPE_WARNING);
expect($result['result'])->equals('Table column added has been dropped');
expect($result['table'])->equals('podium_test');
expect($install->db->schema->getTableSchema("{{%podium_test}}", true)->columns)->hasntKey('added');
}

/**
* @depends testCreateTable
*/
public function testAddIndex()
{
$install = Stub::construct(Installation::className(), [], ['_steps' => $this->steps['addIndexTest']]);
$result = $install->nextStep();
expect($result['drop'])->equals(false);
expect($result['type'])->equals(Installation::TYPE_SUCCESS);
expect($result['result'])->equals('Table index idx-podium_test-sort has been added');
expect($result['table'])->equals('podium_test');
}

/**
* @depends testAddIndex
*/
public function testDropIndex()
{
$install = Stub::construct(Installation::className(), [], ['_steps' => $this->steps['dropIndexTest']]);
$result = $install->nextStep();
expect($result['drop'])->equals(false);
expect($result['type'])->equals(Installation::TYPE_WARNING);
expect($result['result'])->equals('Table index idx-podium_test-sort has been dropped');
expect($result['table'])->equals('podium_test');
}

/**
* @depends testCreateTable
*/
public function testAddForeign()
{
$install = Stub::construct(Installation::className(), [], ['_steps' => $this->steps['addForeignTest']]);
$install->db->createCommand()->createTable('{{%podium_test_foreign}}', [
'id' => Schema::TYPE_PK,
'level' => Schema::TYPE_INTEGER
], $install->tableOptions)->execute();
$result = $install->nextStep();
expect($result['drop'])->equals(false);
expect($result['type'])->equals(Installation::TYPE_SUCCESS);
expect($result['result'])->equals('Table foreign key fk-podium_test-key_f has been added');
expect($result['table'])->equals('podium_test');
}

/**
* @depends testAddForeign
*/
public function testDropForeign()
{
$install = Stub::construct(Installation::className(), [], ['_steps' => $this->steps['dropForeignTest']]);
$result = $install->nextStep();
expect($result['drop'])->equals(false);
expect($result['type'])->equals(Installation::TYPE_WARNING);
expect($result['result'])->equals('Table foreign key fk-podium_test-key_f has been dropped');
expect($result['table'])->equals('podium_test');
$install->db->createCommand()->dropTable("{{%podium_test_foreign}}")->execute();
}

/**
* @depends testCreateTable
*/
public function testAlterColumn()
{
$install = Stub::construct(Installation::className(), [], ['_steps' => $this->steps['alterColumnTest']]);
$result = $install->nextStep();
expect($result['drop'])->equals(false);
expect($result['type'])->equals(Installation::TYPE_SUCCESS);
expect($result['result'])->equals('Table column message has been updated');
expect($result['table'])->equals('podium_test');
}

/**
* @depends testCreateTable
*/
public function testRenameColumn()
{
$install = Stub::construct(Installation::className(), [], ['_steps' => $this->steps['renameColumnTest']]);
$result = $install->nextStep();
expect($result['drop'])->equals(false);
expect($result['type'])->equals(Installation::TYPE_SUCCESS);
expect($result['result'])->equals('Table column message has been renamed to messageRenamed');
expect($result['table'])->equals('podium_test');
expect($install->db->schema->getTableSchema("{{%podium_test}}", true)->columns)->hasntKey('message');
expect($install->db->schema->getTableSchema("{{%podium_test}}", true)->columns)->hasKey('messageRenamed');
}


/**
* @depends testCreateTable
*/
public function testDropTable()
{
\Yii::$app->session->remove(Installation::SESSION_KEY);
$install = Stub::construct(Installation::className(), [], ['_steps' => $this->steps['createTest']]);
$install = Stub::construct(Installation::className(), [], ['_steps' => $this->steps['createTableTest']]);
$result = $install->nextDrop();
expect_that($result['drop']);
expect($result['type'])->equals(Installation::TYPE_WARNING);
expect($result['result'])->equals('Table podium_test has been dropped');
expect($result['table'])->equals('podium_test');
expect_not($install->db->schema->getTableSchema("{{%podium_test}}", true));
}
}

0 comments on commit fe77e58

Please sign in to comment.