Skip to content

Commit

Permalink
Dev: Remove unused code from test
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Jun 26, 2017
1 parent 2c1eed2 commit 9db8cd0
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions tests/helpers/UpdateDbHelperTest.php
Expand Up @@ -17,25 +17,17 @@ public function testBasic()
$db = \Yii::app()->getDb();

$config = require(\Yii::app()->getBasePath() . '/config/config.php');
//var_dump($config);

// Get database name from connection string.
/*
$oldConnectionString = $db->connectionString;
var_dump($db->connectionString);
$arr = explode(';', $db->connectionString);
var_dump($arr);
die;
$this->assertEquals(4, count($ar));
$ar = explode('=', $ar[2]);
$this->assertEquals(2, count($ar));
$this->assertEquals($ar[0], 'dbname');
*/

// Check that we're using MySQL.
$conStr = \Yii::app()->db->connectionString;
$isMysql = substr($conStr, 0, 5) === 'mysql';
if (!$isMysql) {
$this->markTestSkipped('Only works on MySQL');
return;
}
$this->assertTrue($isMysql, 'This test only works on MySQL');

// Get database name.
preg_match("/dbname=([^;]*)/", \Yii::app()->db->connectionString, $matches);
$this->assertEquals(2, count($matches));
$oldDatabase = $matches[1];
Expand All @@ -62,25 +54,32 @@ public function testBasic()
// Run everything
$inst = new \InstallerController('foobar');
$inst->connection = \Yii::app()->db;

// Check SQL file.
$file = __DIR__ . '/../data/sql/create-mysql.153.sql';
$this->assertFileExists($file);

// Run SQL install file.
$result = $inst->_executeSQLFile($file, 'lime_');
var_dump($result);
$this->assertEquals([], $result, 'No error messages');

// Run upgrade.
$result = \db_upgrade_all(153);
var_dump($result);
var_dump(\Yii::app()->user->getFlashes());
$this->assertTrue($result, 'Upgrade successful');

// Check error messages.
$flashes = \Yii::app()->user->getFlashes();
$this->assertEmpty($flashes, 'No flash error messages');

// Connect to old database.
\Yii::app()->setComponent('db', $config['components']['db'], false);
$db->setActive(true);

try {
$result = $db->createCommand('DROP DATABASE __test_update_helper')->execute();
var_dump($result);
//$this->assertEquals(0, $result, 'Could drop database');
} catch (\CDbException $ex) {
$msg = $ex->getMessage();
// This error is OK.
// Only this error is OK.
$this->assertTrue(strpos($msg, 'database doesn\'t exist') !== false);
}
}
Expand Down

0 comments on commit 9db8cd0

Please sign in to comment.