mirror of
https://github.com/Oreolek/yii2-nested-sets.git
synced 2024-06-17 07:10:46 +03:00
Added unit tests for mysql
This commit is contained in:
parent
48d0858138
commit
86a2657c0d
|
@ -7,6 +7,8 @@
|
|||
|
||||
namespace tests;
|
||||
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* DatabaseTestCase
|
||||
*/
|
||||
|
@ -17,7 +19,7 @@ abstract class DatabaseTestCase extends \PHPUnit_Extensions_Database_TestCase
|
|||
*/
|
||||
public function getConnection()
|
||||
{
|
||||
return $this->createDefaultDBConnection(\Yii::$app->db->pdo);
|
||||
return $this->createDefaultDBConnection(Yii::$app->getDb()->pdo);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
39
tests/MysqlNestedSetsBehaviorTest.php
Normal file
39
tests/MysqlNestedSetsBehaviorTest.php
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
/**
|
||||
* @link https://github.com/creocoder/yii2-nested-sets
|
||||
* @copyright Copyright (c) 2015 Alexander Kochetov
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause
|
||||
*/
|
||||
|
||||
namespace tests;
|
||||
|
||||
use Yii;
|
||||
use yii\db\Connection;
|
||||
|
||||
/**
|
||||
* MysqlNestedSetsBehaviorTest
|
||||
*/
|
||||
class MysqlNestedSetsBehaviorTest extends NestedSetsBehaviorTest
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
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'));
|
||||
|
||||
foreach ($lines as $line) {
|
||||
if (trim($line) !== '') {
|
||||
Yii::$app->getDb()->pdo->exec($line);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
39
tests/MysqlNestedSetsQueryBehaviorTest.php
Normal file
39
tests/MysqlNestedSetsQueryBehaviorTest.php
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
/**
|
||||
* @link https://github.com/creocoder/yii2-nested-sets
|
||||
* @copyright Copyright (c) 2015 Alexander Kochetov
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause
|
||||
*/
|
||||
|
||||
namespace tests;
|
||||
|
||||
use Yii;
|
||||
use yii\db\Connection;
|
||||
|
||||
/**
|
||||
* MysqlNestedSetsQueryBehaviorTest
|
||||
*/
|
||||
class MysqlNestedSetsQueryBehaviorTest extends NestedSetsBehaviorTest
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
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'));
|
||||
|
||||
foreach ($lines as $line) {
|
||||
if (trim($line) !== '') {
|
||||
Yii::$app->getDb()->pdo->exec($line);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,6 +9,8 @@ namespace tests;
|
|||
|
||||
use tests\models\MultipleRootsTree;
|
||||
use tests\models\Tree;
|
||||
use Yii;
|
||||
use yii\db\Connection;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
/**
|
||||
|
@ -635,4 +637,24 @@ class NestedSetsBehaviorTest extends DatabaseTestCase
|
|||
$this->assertTrue(Tree::findOne(4)->isLeaf());
|
||||
$this->assertFalse(Tree::findOne(1)->isLeaf());
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
Yii::$app->set('db', [
|
||||
'class' => Connection::className(),
|
||||
'dsn' => 'sqlite::memory:',
|
||||
]);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,8 @@ namespace tests;
|
|||
|
||||
use tests\models\MultipleRootsTree;
|
||||
use tests\models\Tree;
|
||||
use Yii;
|
||||
use yii\db\Connection;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
/**
|
||||
|
@ -41,4 +43,24 @@ class NestedSetsQueryBehaviorTest extends DatabaseTestCase
|
|||
ArrayHelper::toArray(MultipleRootsTree::find()->leaves()->all())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
Yii::$app->set('db', [
|
||||
'class' => Connection::className(),
|
||||
'dsn' => 'sqlite::memory:',
|
||||
]);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,20 +10,5 @@ Yii::setAlias('@tests', __DIR__);
|
|||
|
||||
new \yii\console\Application([
|
||||
'id' => 'unit',
|
||||
'basePath' => __DIR__ . '/..',
|
||||
'components' => [
|
||||
'db' => [
|
||||
'class' => 'yii\db\Connection',
|
||||
'dsn' => 'sqlite::memory:',
|
||||
],
|
||||
],
|
||||
'basePath' => __DIR__,
|
||||
]);
|
||||
|
||||
Yii::$app->db->open();
|
||||
$lines = explode(';', file_get_contents(__DIR__ . '/migrations/sqlite.sql'));
|
||||
|
||||
foreach ($lines as $line) {
|
||||
if (trim($line) !== '') {
|
||||
Yii::$app->db->pdo->exec($line);
|
||||
}
|
||||
}
|
||||
|
|
24
tests/migrations/mysql.sql
Normal file
24
tests/migrations/mysql.sql
Normal file
|
@ -0,0 +1,24 @@
|
|||
/**
|
||||
* MySQL
|
||||
*/
|
||||
|
||||
DROP TABLE IF EXISTS `tree`;
|
||||
|
||||
CREATE TABLE `tree` (
|
||||
`id` INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||
`lft` INT(11) NOT NULL,
|
||||
`rgt` INT(11) NOT NULL,
|
||||
`depth` INT(11) NOT NULL,
|
||||
`name` VARCHAR(255) NOT NULL
|
||||
);
|
||||
|
||||
DROP TABLE IF EXISTS `multiple_roots_tree`;
|
||||
|
||||
CREATE TABLE `multiple_roots_tree` (
|
||||
`id` INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||
`tree` INT(11),
|
||||
`lft` INT(11) NOT NULL,
|
||||
`rgt` INT(11) NOT NULL,
|
||||
`depth` INT(11) NOT NULL,
|
||||
`name` VARCHAR(255) NOT NULL
|
||||
);
|
Loading…
Reference in a new issue