Skip to content

Commit

Permalink
Merge pull request #184 from wp-cli/fix/prefix-db-type-env
Browse files Browse the repository at this point in the history
  • Loading branch information
schlessera committed Oct 18, 2023
2 parents 300ccf3 + 46edfbf commit 3e2db82
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -212,6 +212,7 @@ The following environment variables can be set to override the default database
- `WP_CLI_TEST_DBNAME` is the database that the tests run under (defaults to "wp_cli_test").
- `WP_CLI_TEST_DBUSER` is the user that the tests run under (defaults to "wp_cli_test").
- `WP_CLI_TEST_DBPASS` is the password to use for the above user (defaults to "password1").
- `WP_CLI_TEST_DBTYPE` is the database engine type to use, i.e. "sqlite" for running tests on SQLite instead of MySQL (defaults to "mysql").

Environment variables can be set for the whole session via the following syntax: `export WP_CLI_TEST_DBNAME=custom_db`.

Expand Down
14 changes: 9 additions & 5 deletions src/Context/FeatureContext.php
Expand Up @@ -400,7 +400,7 @@ private static function cache_wp_files() {
self::$cache_dir = sys_get_temp_dir() . '/wp-cli-test-core-download-cache' . $wp_version_suffix;
self::$sqlite_cache_dir = sys_get_temp_dir() . '/wp-cli-test-sqlite-integration-cache';

if ( 'sqlite' === getenv( 'DB_TYPE' ) ) {
if ( 'sqlite' === getenv( 'WP_CLI_TEST_DBTYPE' ) ) {
if ( ! is_readable( self::$sqlite_cache_dir . '/sqlite-database-integration/db.copy' ) ) {
self::download_sqlite_plugin( self::$sqlite_cache_dir );
}
Expand Down Expand Up @@ -603,6 +603,12 @@ public function __construct() {
$this->variables['DB_HOST'] = 'localhost';
}

if ( getenv( 'WP_CLI_TEST_DBTYPE' ) ) {
$this->variables['DB_TYPE'] = getenv( 'WP_CLI_TEST_DBTYPE' );
} else {
$this->variables['DB_TYPE'] = 'mysql';
}

if ( getenv( 'MYSQL_TCP_PORT' ) ) {
$this->variables['MYSQL_PORT'] = getenv( 'MYSQL_TCP_PORT' );
}
Expand All @@ -611,15 +617,13 @@ public function __construct() {
$this->variables['MYSQL_HOST'] = getenv( 'MYSQL_HOST' );
}

if ( 'sqlite' === getenv( 'DB_TYPE' ) ) {
self::$db_type = 'sqlite';
}

self::$db_settings['dbname'] = $this->variables['DB_NAME'];
self::$db_settings['dbuser'] = $this->variables['DB_USER'];
self::$db_settings['dbpass'] = $this->variables['DB_PASSWORD'];
self::$db_settings['dbhost'] = $this->variables['DB_HOST'];

self::$db_type = $this->variables['DB_TYPE'];

$this->variables['CORE_CONFIG_SETTINGS'] = Utils\assoc_args_to_str( self::$db_settings );

$this->drop_db();
Expand Down
4 changes: 2 additions & 2 deletions tests/test-behat-tags.php
Expand Up @@ -34,7 +34,7 @@ protected function tear_down() {
public function test_behat_tags_wp_version_github_token( $env, $expected ) {
$env_wp_version = getenv( 'WP_VERSION' );
$env_github_token = getenv( 'GITHUB_TOKEN' );
$db_type = getenv( 'DB_TYPE' );
$db_type = getenv( 'WP_CLI_TEST_DBTYPE' );

putenv( 'WP_VERSION' );
putenv( 'GITHUB_TOKEN' );
Expand Down Expand Up @@ -138,7 +138,7 @@ public function test_behat_tags_php_version() {

public function test_behat_tags_extension() {
$env_github_token = getenv( 'GITHUB_TOKEN' );
$db_type = getenv( 'DB_TYPE' );
$db_type = getenv( 'WP_CLI_TEST_DBTYPE' );

putenv( 'GITHUB_TOKEN' );

Expand Down
4 changes: 2 additions & 2 deletions utils/behat-tags.php
Expand Up @@ -79,11 +79,11 @@ function version_tags(
$skip_tags[] = '@broken-trunk';
}

if ( 'sqlite' === getenv( 'DB_TYPE' ) ) {
if ( 'sqlite' === getenv( 'WP_CLI_TEST_DBTYPE' ) ) {
$skip_tags[] = '@require-mysql';
}

if ( 'sqlite' !== getenv( 'DB_TYPE' ) ) {
if ( 'sqlite' !== getenv( 'WP_CLI_TEST_DBTYPE' ) ) {
$skip_tags[] = '@require-sqlite';
}

Expand Down

0 comments on commit 3e2db82

Please sign in to comment.