/** * This method is called before the first test of this test class is run. * * An example DSN would be: host=localhost;port=5432;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_SQLSRV_DSN') && !getenv('JTEST_DATABASE_SQLSRV_DSN')) { static::markTestSkipped('The SQL Server driver is not configured.'); } $dsn = defined('JTEST_DATABASE_SQLSRV_DSN') ? JTEST_DATABASE_SQLSRV_DSN : getenv('JTEST_DATABASE_SQLSRV_DSN'); // First let's trim the sqlsrv: part off the front of the DSN if it exists. if (strpos($dsn, 'sqlsrv:') === 0) { $dsn = substr($dsn, 7); } // 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. static::$driver = JDatabaseDriver::getInstance(self::$options); } catch (RuntimeException $e) { static::$driver = null; } // If for some reason an exception object was returned set our database object to null. if (static::$driver instanceof Exception) { static::$driver = null; } // Setup the factory pointer for the driver and stash the old one. self::$stash = JFactory::$database; JFactory::$database = static::$driver; }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @return void */ protected function setUp() { parent::setUp(); // Register the object $this->object = new JSchemaChangeset(static::$driver, __DIR__ . '/stubs'); }
/** * This method is called after the last test of this test class is run. * * @return void * * @since 12.1 */ public static function tearDownAfterClass() { JFactory::$database = self::$stash; self::$driver = null; }