Skip to content

Commit

Permalink
do not catch PDOException when phpunit is running
Browse files Browse the repository at this point in the history
  • Loading branch information
creme332 committed Apr 18, 2024
1 parent f778b45 commit 94e10f8
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/core/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@ trait Database
private static function connect(): PDO
{
$string = "mysql:hostname=" . DB_HOST . ";dbname=" . DB_NAME;
$pdo_object = new PDO($string, DB_USERNAME, DB_PASSWORD);

try {
return new PDO($string, DB_USERNAME, DB_PASSWORD);
} catch (PDOException $e) {
// TODO: Create a page to display the error
Utility::show(
$e
);
die();
// if PHPUnit is not running, handle the exception
if (!defined('PHPUNIT_STEAMY_TESTSUITE')) {
// TODO: Display a user-friendly error message
Utility::show("Sorry, we're unable to process your request at the moment. Please try again later.");
die();
} else {
// if PHPUnit is running, re-throw the exception to allow it to propagate
throw $e;
}
}
return $pdo_object;
}

/**
Expand Down

0 comments on commit 94e10f8

Please sign in to comment.