Skip to content

Commit

Permalink
Makes the test structure more clean an logical.
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoFara committed Jan 2, 2024
1 parent 22eb3a3 commit bd77045
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions tests/DBTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,35 @@

use PHPUnit\Framework\TestCase;

function user_logging()
{
include __DIR__ . "/../connect.inc.php";
$db_schema = __DIR__ . "../db/schema/baseline.sql";
$command = "mysql -u $userid -p$passwd -h $server -e 'USE $dbname'";
exec($command, $output, $returnValue);
if ($returnValue == 1049) {
// Execute the SQL file to install the database
$command = "mysql -u $userid -p$passwd -h $server $dbname < $db_schema";
exec($command, $output, $returnValue);

if ($returnValue != 0) {
die("Cannot login!");
}
}
return array($userid, $passwd, $server, $dbname);

}

class DBTest extends TestCase
{

public function testDatabaseInstallation()
{
include __DIR__ . "/../connect.inc.php";
$db_schema = "db/schema/baseline.sql";
$command = "mysql -u $userid -p$passwd -h $server -e 'USE $dbname'";
exec($command, $output, $returnValue);
if ($returnValue == 1049) {
// Execute the SQL file to install the database
$command = "mysql -u $userid -p$passwd -h $server $dbname < $db_schema";
exec($command, $output, $returnValue);

// Check if installation worked
$this->assertEquals(0, $returnValue, 'Database installation failed');
}
global $DBCONNECTION;
list($userid, $passwd, $server, $dbname) = user_logging();

// Connect to the database and check if necessary tables are created
$conn = connect_to_database(
// Connect to the database
$DBCONNECTION = connect_to_database(
$server, $userid, $passwd, $dbname, $socket ?? ""
);
$this->assertTrue(
Expand Down

0 comments on commit bd77045

Please sign in to comment.