-
Notifications
You must be signed in to change notification settings - Fork 17
Add support to "dump", "populate" and "cleanup" parameters #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
| use Codeception\Exception\ModuleConfig as ModuleConfigException; | ||
| use Codeception\Module; | ||
| use Codeception\TestCase; | ||
| use Codeception\Configuration as Configuration; | ||
|
|
||
| /** | ||
| * MultiDb - Module that allows tests to perform setup queries and assertions across multiple databases. | ||
|
|
@@ -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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This |
||
| 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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
There was a problem hiding this comment.
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 Configurationpart.