Migrator is now able to create real tables.

Because of how WordPress and the dbDelta function works, it's
basically impossile to test it with Unit testing.
We'll have to make sure we properly test this in acceptance testing.
This commit is contained in:
marco
2015-07-30 20:00:58 +02:00
parent 006a1015f0
commit ba436ccc42
3 changed files with 21 additions and 3 deletions

View File

@ -233,6 +233,8 @@ class Initializer {
}
public function install() {
$migrator = new \MailPoet\Config\Migrator;
$migrator->up();
$this->log_version_number();
}

View File

@ -1,14 +1,29 @@
<?php
namespace MailPoet\Config;
use \MailPoet\Config\Env;
if(!defined('ABSPATH')) exit;
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
class Migrator {
function __construct() {
$this->prefix = \MailPoet\Config\Env::$db_prefix;
$this->prefix = Env::$db_prefix . 'mailpoet_';
$this->charset = Env::$db_charset;
}
function up() {
global $wpdb;
dbDelta($this->subscriber());
}
function subscriber() {
$table = $this->prefix . 'subscriber';
$sql = "CREATE TABLE " . $table . " (
id mediumint(9) NOT NULL AUTO_INCREMENT,
name text NOT NULL,
PRIMARY KEY (id)
);";
return $sql;
}
}

View File

@ -4,10 +4,11 @@ use \MailPoet\Config\Migrator;
class MigratorCest {
public function _before() {
$migrator = new Migrator();
$this->migrator = new Migrator();
}
public function itCanBeCreated() {
public function itCreatesTheSubscriberTable() {
// Can't be tested because of WordPress.
}
public function _after() {