diff --git a/src/mantle/testing/class-installation-manager.php b/src/mantle/testing/class-installation-manager.php index d554467ef..c96875b54 100644 --- a/src/mantle/testing/class-installation-manager.php +++ b/src/mantle/testing/class-installation-manager.php @@ -119,6 +119,16 @@ public function theme( string $theme ) { return $this->loaded( fn () => switch_theme( $theme ) ); } + /** + * Alias for `theme()`. + * + * @param string $theme Theme name. + * @return static + */ + public function with_theme( string $theme ) { + return $this->theme( $theme ); + } + /** * Define the active plugins to be set after the installation is loaded. * @@ -129,6 +139,16 @@ public function plugins( array $plugins ) { return $this->loaded( fn () => update_option( 'active_plugins', $plugins ) ); } + /** + * Alias for `plugins()`. + * + * @param array $plugins Plugin files. + * @return static + */ + public function with_plugins( array $plugins ) { + return $this->plugins( $plugins ); + } + /** * Install the Mantle Testing Framework. * diff --git a/src/mantle/testing/class-utils.php b/src/mantle/testing/class-utils.php index e240be100..7d958c10b 100644 --- a/src/mantle/testing/class-utils.php +++ b/src/mantle/testing/class-utils.php @@ -275,16 +275,23 @@ public static function shell_safe( string|bool $string ): string { * not install the WordPress database. * * @param string $directory Directory to install WordPress in. - * @param bool $install_vip_mu_plugins Whether to install VIP MU plugins. - * @param bool $install_object_cache Whether to install the object cache drop-in. + * @param bool $install_vip_mu_plugins Whether to install VIP MU plugins, defaults to false. + * @param bool $install_object_cache Whether to install the object cache drop-in, defaults to false. + * @param bool $use_sqlite_db Whether to use SQLite for the database, defaults to false. */ - public static function install_wordpress( string $directory, bool $install_vip_mu_plugins = false, bool $install_object_cache = false ) { + public static function install_wordpress( + string $directory, + bool $install_vip_mu_plugins = false, + bool $install_object_cache = false, + bool $use_sqlite_db = false, + ): void { $branch = static::env( 'MANTLE_CI_BRANCH', 'HEAD' ); $command = sprintf( - 'export WP_CORE_DIR=%s WP_MULTISITE=%s INSTALL_WP_TEST_DEBUG=%s && curl -s %s | bash -s %s', + 'export WP_CORE_DIR=%s WP_MULTISITE=%s WP_USE_SQLITE=%s INSTALL_WP_TEST_DEBUG=%s && curl -s %s | bash -s %s', $directory, static::shell_safe( static::env( 'WP_MULTISITE', '0' ) ), + static::shell_safe( $use_sqlite_db ), static::shell_safe( static::is_debug_mode() ), "https://raw.githubusercontent.com/alleyinteractive/mantle-ci/{$branch}/install-wp-tests.sh", collect( diff --git a/src/mantle/testing/concerns/trait-rsync-installation.php b/src/mantle/testing/concerns/trait-rsync-installation.php index f5a0d73dc..9d28121bd 100644 --- a/src/mantle/testing/concerns/trait-rsync-installation.php +++ b/src/mantle/testing/concerns/trait-rsync-installation.php @@ -67,6 +67,13 @@ trait Rsync_Installation { */ protected bool $install_object_cache = false; + /** + * Flag to use a SQLite db.php drop-in when rsyncing the codebase. + * + * @var boolean + */ + protected bool $use_sqlite_db = false; + /** * Exclusions to be used when rsyncing the codebase. * @@ -197,6 +204,27 @@ public function with_object_cache( bool $install = true ): static { return $this; } + /** + * Install SQLite db.php drop-in into the codebase. + * + * This will only be applied if the codebase is being rsync-ed to a WordPress + * installation. + * + * @param bool $install Install the SQLite db.php drop-in into the codebase. + * @return static + */ + public function with_sqlite( bool $install = true ): static { + if ( $this->is_within_wordpress_install() ) { + return $this; + } + + $this->rsync_exclusions[] = 'db.php'; + + $this->use_sqlite_db = $install; + + return $this; + } + /** * Maybe rsync the codebase as a plugin within WordPress. * @@ -306,6 +334,7 @@ protected function perform_rsync_testsuite() { directory: $base_install_path, install_vip_mu_plugins: $this->install_vip_mu_plugins, install_object_cache: $this->install_object_cache, + use_sqlite_db: $this->use_sqlite_db, ); Utils::success(