57 lines
1.6 KiB
PHP
57 lines
1.6 KiB
PHP
<?php
|
|
|
|
require_once '../vendor/autoload.php'; // Adjust the path as needed to include Composer's autoload
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use DJMixHosting\Database;
|
|
|
|
class DatabaseTest extends TestCase
|
|
{
|
|
private $config;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
// Setup your test database configuration here
|
|
$this->config = [
|
|
'database' => [
|
|
'host' => 'localhost',
|
|
'user' => 'test_user',
|
|
'pass' => 'test_password',
|
|
'db' => 'test_database',
|
|
'port' => 3306
|
|
]
|
|
];
|
|
}
|
|
|
|
public function testConnection()
|
|
{
|
|
// Create an instance of Database
|
|
$db = new Database($this->config);
|
|
|
|
// Check if the connection is successfully established
|
|
$this->assertInstanceOf(mysqli::class, $db);
|
|
$this->assertEquals(0, $db->connect_errno, "Database connection error: " . $db->connect_error);
|
|
}
|
|
|
|
public function testQuery()
|
|
{
|
|
// Create an instance of Database
|
|
$db = new Database($this->config);
|
|
|
|
// Execute a simple query
|
|
$result = $db->query('SELECT 1 AS value');
|
|
$this->assertNotFalse($result, "Query failed: " . $db->error);
|
|
|
|
$row = $result->fetch_assoc();
|
|
$this->assertEquals(1, $row['value'], "Query did not return the correct value");
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
// Close the database connection if it's still open
|
|
if (isset($db) && $db instanceof mysqli) {
|
|
$db->close();
|
|
}
|
|
}
|
|
}
|