public function _initialize() { if ($this->config['dump'] && ($this->config['cleanup'] or $this->config['populate'])) { if (!file_exists(Configuration::projectDir() . $this->config['dump'])) { throw new ModuleConfigException(__CLASS__, "\n File with dump doesn't exist.\n\n Please, check path for dump file: " . $this->config['dump']); } $this->dumpFile = Configuration::projectDir() . $this->config['dump']; $this->isDumpFileEmpty = false; $content = file_get_contents($this->dumpFile); $content = trim(preg_replace('%/\\*(?:(?!\\*/).)*\\*/%s', "", $content)); if (!sizeof(explode("\n", $content))) { $this->isDumpFileEmpty = true; } } try { $this->driver = MongoDbDriver::create($this->config['dsn'], $this->config['user'], $this->config['password']); } catch (\MongoConnectionException $e) { throw new ModuleException(__CLASS__, $e->getMessage() . ' while creating Mongo connection'); } // starting with loading dump if ($this->config['populate']) { $this->cleanup(); $this->loadDump(); $this->populated = true; } }
public function _initialize() { try { $this->driver = MongoDbDriver::create($this->config['dsn'], $this->config['user'], $this->config['password']); } catch (\MongoConnectionException $e) { throw new ModuleException(__CLASS__, $e->getMessage() . ' while creating Mongo connection'); } // starting with loading dump if ($this->config['populate']) { $this->cleanup(); $this->loadDump(); $this->populated = true; } }
protected function setupDriver($dbName, $config) { if (!empty($config['dump']) && (isset($config['cleanup']) or isset($config['populate']))) { if (!file_exists(Configuration::projectDir() . $config['dump'])) { throw new \Codeception\Exception\ModuleConfig(__CLASS__, "\n File with dump doesn't exist.\n\n Please, check path for dump file: " . $config['dump']); } $dumpFile = Configuration::projectDir() . $config['dump']; $content = file_get_contents($dumpFile); $content = trim(preg_replace('%/\\*(?:(?!\\*/).)*\\*/%s', "", $content)); if (sizeof(explode("\n", $content))) { $this->dumpFiles[$dbName] = $dumpFile; } } try { $this->drivers[$dbName] = MongoDbDriver::create($config['dsn'], $config['user'], $config['password']); } catch (\MongoConnectionException $e) { throw new \Codeception\Exception\Module(__CLASS__, $e->getMessage() . ' while creating Mongo connection'); } $populate = !isset($config['populate']) || isset($config['populate']) && $config['populate'] == false; // starting with loading dump if ($populate) { $this->cleanup($dbName); $this->loadDump($dbName); $this->populated[$dbName] = true; } }