Files
piratepoet/tests/_support/Helper/Database.php
2021-01-18 14:39:42 +01:00

31 lines
797 B
PHP
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Helper;
use MailPoet\Config\Env;
use MailPoetVendor\Idiorm\ORM;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
class Database extends \Codeception\Module {
/**
* Load a SQL file
*
* @param string $filename Filename without extension
*/
static public function loadSQL($filename) {
global $wpdb;
$db = ORM::getDb();
$fullFilename = Env::$path . '/tests/_data/' . $filename . '.sql';
$sql = file_get_contents($fullFilename);
assert(is_string($sql));
$sql = preg_replace('/`wp_/', '`' . $wpdb->prefix, $sql); // Use the current database prefix
if (!is_string($sql)) {
throw new \RuntimeException('Empty or missing ' . $fullFilename);
}
$db->exec($sql);
}
}