Add db source name to Env.
This commit is contained in:
@@ -6,7 +6,9 @@ if(!defined('ABSPATH')) exit;
|
||||
class Env {
|
||||
public static $plugin_prefix;
|
||||
public static $db_prefix;
|
||||
public static $db_source_name;
|
||||
public static $db_host;
|
||||
public static $db_name;
|
||||
public static $db_username;
|
||||
public static $db_password;
|
||||
public static $db_charset;
|
||||
@@ -15,9 +17,22 @@ class Env {
|
||||
global $wpdb;
|
||||
self::$plugin_prefix = 'mailpoet_';
|
||||
self::$db_prefix = $wpdb->prefix;
|
||||
self::$db_source_name = self::dbSourceName();
|
||||
self::$db_host = DB_HOST;
|
||||
self::$db_name = DB_NAME;
|
||||
self::$db_username = DB_USER;
|
||||
self::$db_password = DB_PASSWORD;
|
||||
self::$db_charset = $wpdb->get_charset_collate();
|
||||
}
|
||||
|
||||
public static function dbSourceName() {
|
||||
$source_name = array(
|
||||
'mysql:host=',
|
||||
Env::$db_host,
|
||||
';',
|
||||
'dbname=',
|
||||
Env::$db_name
|
||||
);
|
||||
return implode('', $source_name);
|
||||
}
|
||||
}
|
||||
|
@@ -19,6 +19,10 @@ class Initializer {
|
||||
'version' => '1.0.0'
|
||||
)) {
|
||||
Env::init();
|
||||
/* ORM::configure('mysql:host=localhost;dbname=my_database'); */
|
||||
/* ORM::configure('username', Env::$db_username); */
|
||||
/* ORM::configure('password', Env::$db_password); */
|
||||
|
||||
$this->data = array();
|
||||
$this->version = $params['version'];
|
||||
$this->shortname = 'wysija-newsletters';
|
||||
|
@@ -3,38 +3,47 @@ use \UnitTester;
|
||||
use \MailPoet\Config\Env;
|
||||
|
||||
class EnvCest {
|
||||
public function _before() {
|
||||
function _before() {
|
||||
Env::init();
|
||||
}
|
||||
|
||||
public function itCanReturnThePluginPrefix() {
|
||||
function itCanReturnThePluginPrefix() {
|
||||
expect(Env::$plugin_prefix)->equals('mailpoet_');
|
||||
}
|
||||
|
||||
public function itCanReturnTheDbPrefix() {
|
||||
function itCanReturnTheDbPrefix() {
|
||||
global $wpdb;
|
||||
$db_prefix = $wpdb->prefix;
|
||||
expect(Env::$db_prefix)->equals($db_prefix);
|
||||
}
|
||||
|
||||
public function itCanReturnTheDbHost() {
|
||||
function itCanReturnTheDbHost() {
|
||||
expect(Env::$db_host)->equals(DB_HOST);
|
||||
}
|
||||
|
||||
public function itCanReturnTheDbUser() {
|
||||
function itCanReturnTheDbName() {
|
||||
expect(Env::$db_name)->equals(DB_NAME);
|
||||
}
|
||||
|
||||
function itCanReturnTheDbUser() {
|
||||
expect(Env::$db_username)->equals(DB_USER);
|
||||
}
|
||||
|
||||
public function itCanReturnTheDbPassword() {
|
||||
function itCanReturnTheDbPassword() {
|
||||
expect(Env::$db_password)->equals(DB_PASSWORD);
|
||||
}
|
||||
|
||||
public function itCanReturnTheDbCharset() {
|
||||
function itCanReturnTheDbCharset() {
|
||||
global $wpdb;
|
||||
$charset = $wpdb->get_charset_collate();
|
||||
expect(Env::$db_charset)->equals($charset);
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
function itCanGenerateTheDbSourceName() {
|
||||
$source_name = 'mysql:host=' . DB_HOST . ';dbname=' . DB_NAME;
|
||||
expect(Env::$db_source_name)->equals($source_name);
|
||||
}
|
||||
|
||||
function _after() {
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user