PHPUnit stuff.
This commit is contained in:
parent
91dc776e4d
commit
74f1d6e193
30 changed files with 358 additions and 89 deletions
56
tests/DatabaseTest.php
Normal file
56
tests/DatabaseTest.php
Normal file
|
@ -0,0 +1,56 @@
|
|||
<?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();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue