Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ phpunit.phar
tests/_app/config/db.local.php
tests/_support/_generated
tests/_output/*

# composer lock file
composer.lock
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 7 additions & 0 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,11 @@ class Module extends BaseModule
'recover/<id:\d+>/<code:[A-Za-z0-9_-]+>' => 'recovery/reset',
'settings/<action:\w+>' => 'settings/<action>'
];

/** @var string The database connection to use for models in this module. */
public $dbConnection = 'db';

public function getDb() {
return \Yii::$app->get($this->dbConnection);
}
}
1 change: 1 addition & 0 deletions codeception.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ modules:
config:
Yii2:
configFile: 'tests/_app/config/test.php'
cleanup: false
coverage:
enabled: true
include:
Expand Down
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"homepage": "http://dmeroff.ru"
}
],
"minimum-stability": "dev",
"require": {
"yiisoft/yii2": "^2.0.0",
"yiisoft/yii2-swiftmailer": "^2.0.0",
Expand Down
11 changes: 4 additions & 7 deletions tests/_app/config/db.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
3 changes: 3 additions & 0 deletions tests/_app/config/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
],
],
'components' => [
'session' => [

],
'db' => require __DIR__ . '/db.php',
'mailer' => [
'useFileTransport' => true,
Expand Down
1 change: 1 addition & 0 deletions tests/_fixtures/data/sql/database.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
create database dektrium_test;
7 changes: 7 additions & 0 deletions tests/runtests.sh
Original file line number Diff line number Diff line change
@@ -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 $@
5 changes: 5 additions & 0 deletions traits/ModuleTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ public function getModule()
{
return \Yii::$app->getModule('user');
}

public static function getDb()
{
return \Yii::$app->getModule('user')->getDb();
}
}