1
0
Fork 0
mirror of https://github.com/Oreolek/yii2-nested-sets.git synced 2024-06-17 07:10:46 +03:00

Refactored unit tests

This commit is contained in:
Alexander Kochetov 2015-01-16 00:52:07 +03:00
parent e6dbf19ebb
commit e1cc6d77e6
5 changed files with 68 additions and 40 deletions

View file

@ -29,4 +29,16 @@ abstract class DatabaseTestCase extends \PHPUnit_Extensions_Database_TestCase
{
return $this->createFlatXMLDataSet(__DIR__ . '/data/test.xml');
}
/**
* @inheritdoc
*/
protected function setUp()
{
if (Yii::$app->get('db', false) === null) {
$this->markTestSkipped();
} else {
parent::setUp();
}
}
}

View file

@ -20,20 +20,24 @@ class MysqlNestedSetsBehaviorTest extends NestedSetsBehaviorTest
*/
public static function setUpBeforeClass()
{
Yii::$app->set('db', [
'class' => Connection::className(),
'dsn' => 'mysql:host=localhost;dbname=yii2_nested_sets_test',
'username' => 'root',
'password' => '',
]);
try {
Yii::$app->set('db', [
'class' => Connection::className(),
'dsn' => 'mysql:host=localhost;dbname=yii2_nested_sets_test',
'username' => 'root',
'password' => '',
]);
Yii::$app->getDb()->open();
$lines = explode(';', file_get_contents(__DIR__ . '/migrations/mysql.sql'));
Yii::$app->getDb()->open();
$lines = explode(';', file_get_contents(__DIR__ . '/migrations/mysql.sql'));
foreach ($lines as $line) {
if (trim($line) !== '') {
Yii::$app->getDb()->pdo->exec($line);
foreach ($lines as $line) {
if (trim($line) !== '') {
Yii::$app->getDb()->pdo->exec($line);
}
}
} catch (\Exception $e) {
Yii::$app->clear('db');
}
}
}

View file

@ -20,20 +20,24 @@ class MysqlNestedSetsQueryBehaviorTest extends NestedSetsBehaviorTest
*/
public static function setUpBeforeClass()
{
Yii::$app->set('db', [
'class' => Connection::className(),
'dsn' => 'mysql:host=localhost;dbname=yii2_nested_sets_test',
'username' => 'root',
'password' => '',
]);
try {
Yii::$app->set('db', [
'class' => Connection::className(),
'dsn' => 'mysql:host=localhost;dbname=yii2_nested_sets_test',
'username' => 'root',
'password' => '',
]);
Yii::$app->getDb()->open();
$lines = explode(';', file_get_contents(__DIR__ . '/migrations/mysql.sql'));
Yii::$app->getDb()->open();
$lines = explode(';', file_get_contents(__DIR__ . '/migrations/mysql.sql'));
foreach ($lines as $line) {
if (trim($line) !== '') {
Yii::$app->getDb()->pdo->exec($line);
foreach ($lines as $line) {
if (trim($line) !== '') {
Yii::$app->getDb()->pdo->exec($line);
}
}
} catch (\Exception $e) {
Yii::$app->clear('db');
}
}
}

View file

@ -643,18 +643,22 @@ class NestedSetsBehaviorTest extends DatabaseTestCase
*/
public static function setUpBeforeClass()
{
Yii::$app->set('db', [
'class' => Connection::className(),
'dsn' => 'sqlite::memory:',
]);
try {
Yii::$app->set('db', [
'class' => Connection::className(),
'dsn' => 'sqlite::memory:',
]);
Yii::$app->getDb()->open();
$lines = explode(';', file_get_contents(__DIR__ . '/migrations/sqlite.sql'));
Yii::$app->getDb()->open();
$lines = explode(';', file_get_contents(__DIR__ . '/migrations/sqlite.sql'));
foreach ($lines as $line) {
if (trim($line) !== '') {
Yii::$app->getDb()->pdo->exec($line);
foreach ($lines as $line) {
if (trim($line) !== '') {
Yii::$app->getDb()->pdo->exec($line);
}
}
} catch (\Exception $e) {
Yii::$app->clear('db');
}
}
}

View file

@ -49,18 +49,22 @@ class NestedSetsQueryBehaviorTest extends DatabaseTestCase
*/
public static function setUpBeforeClass()
{
Yii::$app->set('db', [
'class' => Connection::className(),
'dsn' => 'sqlite::memory:',
]);
try {
Yii::$app->set('db', [
'class' => Connection::className(),
'dsn' => 'sqlite::memory:',
]);
Yii::$app->getDb()->open();
$lines = explode(';', file_get_contents(__DIR__ . '/migrations/sqlite.sql'));
Yii::$app->getDb()->open();
$lines = explode(';', file_get_contents(__DIR__ . '/migrations/sqlite.sql'));
foreach ($lines as $line) {
if (trim($line) !== '') {
Yii::$app->getDb()->pdo->exec($line);
foreach ($lines as $line) {
if (trim($line) !== '') {
Yii::$app->getDb()->pdo->exec($line);
}
}
} catch (\Exception $e) {
Yii::$app->clear('db');
}
}
}