/** * This method is called before the first test of this test class is run. * * An example DSN would be: host=localhost;dbname=joomla_ut;user=utuser;pass=ut1234 * * @return void * * @since 12.1 */ public static function setUpBeforeClass() { // First let's look to see if we have a DSN defined or in the environment variables. if (defined('JTEST_DATABASE_MYSQLI_DSN') || getenv('JTEST_DATABASE_MYSQLI_DSN')) { $dsn = defined('JTEST_DATABASE_MYSQLI_DSN') ? JTEST_DATABASE_MYSQLI_DSN : getenv('JTEST_DATABASE_MYSQLI_DSN'); } else { return; } // First let's trim the mysql: part off the front of the DSN if it exists. if (strpos($dsn, 'mysql:') === 0) { $dsn = substr($dsn, 6); } // Split the DSN into its parts over semicolons. $parts = explode(';', $dsn); // Parse each part and populate the options array. foreach ($parts as $part) { list($k, $v) = explode('=', $part, 2); switch ($k) { case 'host': self::$_options['host'] = $v; break; case 'dbname': self::$_options['database'] = $v; break; case 'user': self::$_options['user'] = $v; break; case 'pass': self::$_options['password'] = $v; break; } } try { // Attempt to instantiate the driver. self::$driver = JDatabaseDriver::getInstance(self::$_options); } catch (RuntimeException $e) { self::$driver = null; } // If for some reason an exception object was returned set our database object to null. if (self::$driver instanceof Exception) { self::$driver = null; } // Setup the factory pointer for the driver and stash the old one. self::$_stash = JFactory::$database; JFactory::$database = self::$driver; }