Skip to content
Merged
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
50 changes: 50 additions & 0 deletions src/Codeception/Extension/MultiDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Codeception\Exception\ModuleConfig as ModuleConfigException;
use Codeception\Module;
use Codeception\TestCase;
use Codeception\Configuration as Configuration;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary aliasing; really dont need the as Configuration part.


/**
* MultiDb - Module that allows tests to perform setup queries and assertions across multiple databases.
Expand Down Expand Up @@ -85,6 +86,55 @@ public function _initialize()
$this->timezone = $this->config['timezone'];

parent::_initialize();

foreach ($this->config['connectors'] as $connector => $connectorConfig) {
if ($connectorConfig['populate']) {
if ($connectorConfig['cleanup']) {
$this->cleanup($connector);
}
$this->loadDump($connector);
}
}
}

protected function loadDump($connector)
Copy link
Contributor

@codemedic codemedic Jun 17, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHPDoc Comments missing; but never mind I will add that this time :)

{
$config = $this->config['connectors'][$connector];

if ($config['dump'] && ($config['cleanup'] or ($config['populate']))) {
if (!file_exists(Configuration::projectDir() . $config['dump'])) {
throw new ModuleConfigException(
__CLASS__,
"\nFile with dump doesn't exist.
Please, check path for sql file: " . $config['dump']
);
}
$sql = file_get_contents(Configuration::projectDir() . $config['dump']);
$sql = preg_replace('%/\*(?!!\d+)(?:(?!\*/).)*\*/%s', "", $sql);
if (!empty($sql)) {
$sql = explode("\n", $sql);
}
}
if (!$sql) {
Copy link
Contributor

@codemedic codemedic Jun 17, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if and the try/catch below (with its contents) can be merged with if (!empty($sql)) { block.

return;
}
try {
$this->getDriver($connector)->load($sql);
} catch (\PDOException $e) {
throw new ModuleException(
__CLASS__,
$e->getMessage() . "\nSQL query being executed: " . $sql
);
}
}

protected function cleanup($connector)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHPDoc Comments missing; but never mind I will add that this time :)

{
try {
$this->getDriver($connector)->cleanup();
} catch (\Exception $e) {
throw new ModuleException(__CLASS__, $e->getMessage());
}
}

// HOOK: before scenario
Expand Down