From 33a2e002afa2cf143db65b416779768fad8b68e8 Mon Sep 17 00:00:00 2001 From: Alda Vigdis Skarphedinsdottir Date: Fri, 22 Mar 2024 02:09:43 +0100 Subject: [PATCH] Always dropping and rebuilding the config file on a new run (#27) --- src/Bootstrap.php | 103 ++++++++++++++++++++++------------------------ src/Config.php | 8 ++++ 2 files changed, 57 insertions(+), 54 deletions(-) diff --git a/src/Bootstrap.php b/src/Bootstrap.php index 7f7937e..18a3a07 100644 --- a/src/Bootstrap.php +++ b/src/Bootstrap.php @@ -220,74 +220,69 @@ public static function init(string $wp_version): void echo PHP_EOL; - if (self::configExsists() === false) { - self::displayLine( - 'A test config file for the WordPress test environment was ' . - 'not found.', - '👀' - ); + if (self::configExsists() === true) { + self::displayLine('Dropping the older config file.', '♻️'); + } - $config = new Config(wp_version: $wp_version); + $config = new Config(wp_version: $wp_version); - if ($config->save() === true) { - $path = Config::path(); - self::displayLine("A fresh config was saved to '$path'."); - echo PHP_EOL; - } + if ($config->save() === true) { + $path = Config::path(); + self::displayLine("A fresh config was saved to '$path'."); + echo PHP_EOL; + } - if ( - Database::testConnection( - $config->db_host, - $config->db_user, - $config->db_password, - $config->db_name - ) === true - ) { - self::displayLine( - 'Connection to the database server was successful.' - ); - } else { - self::displayLine( - 'Unable to connect to the database. Check if the ' . - 'database name, hostname, username or password are valid ' . - 'and correct.', - '👎' - ); - } + if ( + Database::testConnection( + $config->db_host, + $config->db_user, + $config->db_password, + $config->db_name + ) === true + ) { + self::displayLine( + 'Connection to the database server was successful.' + ); + } else { + self::displayLine( + 'Unable to connect to the database. Check if the ' . + 'database name, hostname, username or password are valid ' . + 'and correct.', + '👎' + ); + } + if ( + Database::exsists( + $config->db_host, + $config->db_user, + $config->db_password, + $config->db_name + ) === true + ) { + self::displayLine( + "The '$config->db_name' database exsists." + ); + } else { + self::displayLine( + "The '$config->db_name' database does not exist." . + 'Attempting to create it...', + '😰' + ); if ( - Database::exsists( + Database::create( $config->db_host, $config->db_user, $config->db_password, $config->db_name ) === true ) { - self::displayLine( - "The '$config->db_name' database exsists." - ); - } else { - self::displayLine( - "The '$config->db_name' database does not exist." . - 'Attempting to create it...', - '😰' - ); - if ( - Database::create( - $config->db_host, - $config->db_user, - $config->db_password, - $config->db_name - ) === true - ) { - self::displayLine('The database was created.'); - } + self::displayLine('The database was created.'); } - - echo PHP_EOL; - } + echo PHP_EOL; + if (FetchWP::isInstalled('develop-trunk', 'wordpress') === false) { self::displayLine( 'A WordPress develop-trunk environment was not found.', diff --git a/src/Config.php b/src/Config.php index 94ff14c..8018695 100644 --- a/src/Config.php +++ b/src/Config.php @@ -180,6 +180,14 @@ public function save(): bool return false; } + /** + * Delete the config file + */ + public function drop(): bool + { + return unlink(self::path()); + } + /** * Format a comment block for the configuration file */