public function testConnectionError() { $string_dsn = $this->properties[$this->properties['xpdo_driver'] . '_string_dsn_error']; $mypdo = new xPDO($string_dsn, "nonesuchuser", "nonesuchpass"); $result = $mypdo->connect(); // Should be an error set since we gave bogus info $this->assertTrue($result == false, "Connection was successful with bogus information."); }
/** * Test for a bogus false connection. * * @TODO Fix this, it seems to cause a timeout and a stall of PHPUnit. */ public function testConnectionError() { if (!empty(xPDOTestHarness::$debug)) { print "\n" . __METHOD__ . " = "; } $string_dsn = xPDOTestHarness::$properties[xPDOTestHarness::$properties['xpdo_driver'] . '_string_dsn_error']; $mypdo = new xPDO($string_dsn, "nonesuchuser", "nonesuchpass"); $result = $mypdo->connect(); // Should be an error set since we gave bogus info $this->assertTrue($result == false, "Connection was successful with bogus information."); }
/** * Get an xPDO connection to the database. * * @param int $mode * @return xPDO A copy of the xpdo object. */ public function getConnection($mode = 0) { if ($this->settings && empty($mode)) { $mode = (int) $this->settings->get('installmode'); } if (empty($mode)) { $mode = modInstall::MODE_NEW; } if ($mode === modInstall::MODE_UPGRADE_REVO) { $errors = array(); $this->xpdo = $this->_modx($errors); } else { if (!is_object($this->xpdo)) { $options = array(); if ($this->settings->get('new_folder_permissions')) { $options['new_folder_permissions'] = $this->settings->get('new_folder_permissions'); } if ($this->settings->get('new_file_permissions')) { $options['new_file_permissions'] = $this->settings->get('new_file_permissions'); } $this->xpdo = $this->_connect($this->settings->get('database_dsn'), $this->settings->get('database_user'), $this->settings->get('database_password'), $this->settings->get('table_prefix'), $options); if (!$this->xpdo instanceof xPDO) { return $this->xpdo; } $this->xpdo->setOption('cache_path', MODX_CORE_PATH . 'cache/'); if ($mode === modInstall::MODE_UPGRADE_REVO_ADVANCED) { if ($this->xpdo->connect()) { $errors = array(); $this->xpdo = $this->_modx($errors); } else { return $this->lexicon('db_err_connect_upgrade'); } } } } if (is_object($this->xpdo) && $this->xpdo instanceof xPDO) { $this->xpdo->setLogTarget(array('target' => 'FILE', 'options' => array('filename' => 'install.' . MODX_CONFIG_KEY . '.' . strftime('%Y-%m-%dT%H.%M.%S') . '.log'))); $this->xpdo->setLogLevel(xPDO::LOG_LEVEL_ERROR); $this->xpdo->setPackage('modx', MODX_CORE_PATH . 'model/', $this->settings->get('table_prefix')); } return $this->xpdo; }