Skip to content

Commit

Permalink
Always dropping and rebuilding the config file on a new run (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
aldavigdis authored Mar 22, 2024
1 parent a028cfb commit 33a2e00
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 54 deletions.
103 changes: 49 additions & 54 deletions src/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down
8 changes: 8 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 33a2e00

Please sign in to comment.