diff --git a/.gitignore b/.gitignore index c3b3785d1..f1ec7f109 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,6 @@ phpunit.phar tests/_app/config/db.local.php tests/_support/_generated tests/_output/* + +# composer lock file +composer.lock diff --git a/.travis.yml b/.travis.yml index f06155367..a3844023b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,14 @@ language: php php: + - 7.1 - 7.0 - 5.6 - - 5.5 - - 5.4 +services: + - mysql # environment variable used in test suite -env: TEST_ENVIRONMENT=travis +env: TEST_ENVIRONMENT=travis MYSQL_HOST=localhost MYSQL_USER=root MYSQL_PASSWORD="" MYSQL_DATABASE="dektrium_test" # faster builds on new travis setup not using sudo sudo: false diff --git a/Module.php b/Module.php index d325ee8ce..e81d30abb 100644 --- a/Module.php +++ b/Module.php @@ -107,4 +107,11 @@ class Module extends BaseModule 'recover//' => 'recovery/reset', 'settings/' => 'settings/' ]; + + /** @var string The database connection to use for models in this module. */ + public $dbConnection = 'db'; + + public function getDb() { + return \Yii::$app->get($this->dbConnection); + } } diff --git a/codeception.yml b/codeception.yml index 320f078a7..ab42b9c18 100644 --- a/codeception.yml +++ b/codeception.yml @@ -12,6 +12,7 @@ modules: config: Yii2: configFile: 'tests/_app/config/test.php' + cleanup: false coverage: enabled: true include: diff --git a/composer.json b/composer.json index 53fbc0dc0..eb7e6f3a4 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,6 @@ "homepage": "http://dmeroff.ru" } ], - "minimum-stability": "dev", "require": { "yiisoft/yii2": "^2.0.0", "yiisoft/yii2-swiftmailer": "^2.0.0", diff --git a/tests/_app/config/db.php b/tests/_app/config/db.php index 24b10a453..56eb3f47b 100644 --- a/tests/_app/config/db.php +++ b/tests/_app/config/db.php @@ -2,14 +2,11 @@ $db = [ 'class' => 'yii\db\Connection', - 'dsn' => 'mysql:host=localhost;dbname=dektrium_test', - 'username' => 'root', - 'password' => '', + 'dsn' => 'mysql:host=' . getenv('DB_HOST') . ';dbname=' . getenv('MYSQL_DATABASE'), + 'password' => getenv('MYSQL_PASSWORD'), + 'username' => getenv('MYSQL_USER'), 'charset' => 'utf8', +// 'enableSavepoint' => false ]; -if (file_exists(__DIR__ . '/db.local.php')) { - $db = array_merge($db, require(__DIR__ . '/db.local.php')); -} - return $db; \ No newline at end of file diff --git a/tests/_app/config/test.php b/tests/_app/config/test.php index 92b3aca4d..1ed000885 100644 --- a/tests/_app/config/test.php +++ b/tests/_app/config/test.php @@ -18,6 +18,9 @@ ], ], 'components' => [ + 'session' => [ + + ], 'db' => require __DIR__ . '/db.php', 'mailer' => [ 'useFileTransport' => true, diff --git a/tests/_fixtures/data/sql/database.sql b/tests/_fixtures/data/sql/database.sql new file mode 100644 index 000000000..df64bbddb --- /dev/null +++ b/tests/_fixtures/data/sql/database.sql @@ -0,0 +1 @@ +create database dektrium_test; \ No newline at end of file diff --git a/tests/runtests.sh b/tests/runtests.sh new file mode 100755 index 000000000..8827acbbb --- /dev/null +++ b/tests/runtests.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +composer install --prefer-dist + +php tests/_app/yii.php migrate --migrationPath=@dektrium/user/migrations --interactive=0 + +exec /bin/codecept $@ \ No newline at end of file diff --git a/traits/ModuleTrait.php b/traits/ModuleTrait.php index c2031a942..1d7a0d342 100644 --- a/traits/ModuleTrait.php +++ b/traits/ModuleTrait.php @@ -19,4 +19,9 @@ public function getModule() { return \Yii::$app->getModule('user'); } + + public static function getDb() + { + return \Yii::$app->getModule('user')->getDb(); + } }