Skip to content

Instantly share code, notes, and snippets.

@pento
Created December 30, 2015 03:07
Show Gist options
  • Save pento/25052b257a807687785d to your computer and use it in GitHub Desktop.
Save pento/25052b257a807687785d to your computer and use it in GitHub Desktop.
MySQL version switching with MySQL Sandbox
<?php
/* Path to the WordPress codebase you'd like to test. Add a backslash in the end. */
define( 'ABSPATH', dirname( __FILE__ ) . '/src/' );
// Test with multisite enabled.
// Alternatively, use the tests/phpunit/multisite.xml configuration file.
// define( 'WP_TESTS_MULTISITE', true );
// Force known bugs to be run.
// Tests with an associated Trac ticket that is still open are normally skipped.
// define( 'WP_TESTS_FORCE_KNOWN_BUGS', true );
// Test with WordPress debug mode (default).
define( 'WP_DEBUG', true );
// ** MySQL settings ** //
// This configuration file will be used by the copy of WordPress being tested.
// wordpress/wp-config.php will be ignored.
// WARNING WARNING WARNING!
// These tests will DROP ALL TABLES in the database with the prefix named below.
// DO NOT use a production database or one that is shared with something else.
$current_db = '5.6.17';
if ( $current_db ) {
define( 'DB_USER', 'msandbox' );
define( 'DB_PASSWORD', 'msandbox' );
exec( '~/sandboxes/msb_' . str_replace( '.', '_', $current_db ) . '/start' );
if ( false === strpos( $GLOBALS['argv'][0], 'install.php' ) ) {
register_shutdown_function( 'exec', '~/sandboxes/msb_' . str_replace( '.', '_', $current_db ) . '/stop' );
}
} else {
define( 'DB_USER', 'wp' );
define( 'DB_PASSWORD', 'wp' );
}
switch( $current_db ) {
case '5.0.88':
define( 'DB_HOST', '127.0.0.1:5088' );
break;
case '5.0.96':
define( 'DB_HOST', '127.0.0.1:5096' );
break;
case '5.6.17':
define( 'DB_HOST', '127.0.0.1:5617' );
break;
default:
define( 'DB_HOST', 'localhost' );
break;
}
define( 'DB_NAME', 'wordpress_unit_tests' );
define( 'DB_CHARSET', 'utf8' );
define( 'DB_COLLATE', '' );
$table_prefix = 'wptests_'; // Only numbers, letters, and underscores please!
define( 'WP_TESTS_DOMAIN', 'example.org' );
define( 'WP_TESTS_EMAIL', 'admin@example.org' );
define( 'WP_TESTS_TITLE', 'Test Blog' );
define( 'WP_PHP_BINARY', 'php' );
define( 'WPLANG', '' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment