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:
@ -233,6 +233,8 @@ class Initializer {
|
||||
}
|
||||
|
||||
public function install() {
|
||||
$migrator = new \MailPoet\Config\Migrator;
|
||||
$migrator->up();
|
||||
$this->log_version_number();
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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() {
|
||||
|
Reference in New Issue
Block a user