Skip to content

Commit 3e2db82

Browse files
authored
Merge pull request #184 from wp-cli/fix/prefix-db-type-env
2 parents 300ccf3 + 46edfbf commit 3e2db82

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ The following environment variables can be set to override the default database
212212
- `WP_CLI_TEST_DBNAME` is the database that the tests run under (defaults to "wp_cli_test").
213213
- `WP_CLI_TEST_DBUSER` is the user that the tests run under (defaults to "wp_cli_test").
214214
- `WP_CLI_TEST_DBPASS` is the password to use for the above user (defaults to "password1").
215+
- `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").
215216

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

src/Context/FeatureContext.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ private static function cache_wp_files() {
400400
self::$cache_dir = sys_get_temp_dir() . '/wp-cli-test-core-download-cache' . $wp_version_suffix;
401401
self::$sqlite_cache_dir = sys_get_temp_dir() . '/wp-cli-test-sqlite-integration-cache';
402402

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

606+
if ( getenv( 'WP_CLI_TEST_DBTYPE' ) ) {
607+
$this->variables['DB_TYPE'] = getenv( 'WP_CLI_TEST_DBTYPE' );
608+
} else {
609+
$this->variables['DB_TYPE'] = 'mysql';
610+
}
611+
606612
if ( getenv( 'MYSQL_TCP_PORT' ) ) {
607613
$this->variables['MYSQL_PORT'] = getenv( 'MYSQL_TCP_PORT' );
608614
}
@@ -611,15 +617,13 @@ public function __construct() {
611617
$this->variables['MYSQL_HOST'] = getenv( 'MYSQL_HOST' );
612618
}
613619

614-
if ( 'sqlite' === getenv( 'DB_TYPE' ) ) {
615-
self::$db_type = 'sqlite';
616-
}
617-
618620
self::$db_settings['dbname'] = $this->variables['DB_NAME'];
619621
self::$db_settings['dbuser'] = $this->variables['DB_USER'];
620622
self::$db_settings['dbpass'] = $this->variables['DB_PASSWORD'];
621623
self::$db_settings['dbhost'] = $this->variables['DB_HOST'];
622624

625+
self::$db_type = $this->variables['DB_TYPE'];
626+
623627
$this->variables['CORE_CONFIG_SETTINGS'] = Utils\assoc_args_to_str( self::$db_settings );
624628

625629
$this->drop_db();

tests/test-behat-tags.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected function tear_down() {
3434
public function test_behat_tags_wp_version_github_token( $env, $expected ) {
3535
$env_wp_version = getenv( 'WP_VERSION' );
3636
$env_github_token = getenv( 'GITHUB_TOKEN' );
37-
$db_type = getenv( 'DB_TYPE' );
37+
$db_type = getenv( 'WP_CLI_TEST_DBTYPE' );
3838

3939
putenv( 'WP_VERSION' );
4040
putenv( 'GITHUB_TOKEN' );
@@ -138,7 +138,7 @@ public function test_behat_tags_php_version() {
138138

139139
public function test_behat_tags_extension() {
140140
$env_github_token = getenv( 'GITHUB_TOKEN' );
141-
$db_type = getenv( 'DB_TYPE' );
141+
$db_type = getenv( 'WP_CLI_TEST_DBTYPE' );
142142

143143
putenv( 'GITHUB_TOKEN' );
144144

utils/behat-tags.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ function version_tags(
7979
$skip_tags[] = '@broken-trunk';
8080
}
8181

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

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

0 commit comments

Comments
 (0)