Namespaces changes

This commit is contained in:
2025-09-30 17:15:39 -03:00
parent ed45901de2
commit d2c37d0aad
24 changed files with 289 additions and 217 deletions

View File

@ -1,65 +1,61 @@
<?php
use PHPUnit\Framework\TestCase;
use ProVM\Database\Connection;
use ProVM\Concept;
use Database\Implement\Connection;
use Database\Define;
class ConnectionTest extends TestCase
{
protected string $host = '/tmp/test.db3';
protected string $tableName = 'test_table';
protected PDO $pdo;
protected function setUp(): void
{
$this->pdo = new PDO('sqlite::memory:');
$query = "CREATE TABLE IF NOT EXISTS test_table (id INTEGER PRIMARY KEY, test TEXT)";
$this->pdo = new PDO("sqlite:{$this->host}");
$query = "CREATE TABLE IF NOT EXISTS {$this->tableName} (id INTEGER PRIMARY KEY, test TEXT)";
$this->pdo->query($query);
$query = "INSERT INTO {$this->tableName} (test) VALUES ('test')";
$this->pdo->query($query);
}
protected function tearDown(): void
{
unset($this->pdo);
unlink($this->host);
}
protected function getConnection(): Connection
{
$host = $this->host;
$database = $this->getMockBuilder(Define\Database::class)->getMock();
$database->method('getHost')->willReturn($host);
$database->method('getDsn')->willReturn("sqlite:{$host}");
$database->method('needsUser')->willReturn(false);
return new Connection($database);
}
public function testConnection()
{
$host = "memory";
$database = $this->getMockBuilder(Concept\Database::class)->getMock();
$database->method('getHost')->willReturn($host);
$database->method('getDsn')->willReturn("sqlite::{$host}");
$database->method('needsUser')->willReturn(false);
$connection = new Connection($database);
$this->assertEquals($this->pdo, $connection->connect());
$connection = $this->getConnection();
$this->assertEquals($this->pdo, $connection->getPDO());
}
public function testQuery()
{
$host = "memory";
$database = $this->getMockBuilder(Concept\Database::class)->getMock();
$database->method('getHost')->willReturn($host);
$database->method('getDsn')->willReturn("sqlite::{$host}");
$database->method('needsUser')->willReturn(false);
$connection = new Connection($database);
$connection = $this->getConnection();
$query = "CREATE TABLE IF NOT EXISTS test_table (id INTEGER PRIMARY KEY, test TEXT)";
$connection->query($query);
$query = "SELECT * FROM test_table";
$result = $connection->query($query);
$this->assertInstanceOf(Concept\Database\ResultSet::class, $result);
$connection->query($query);
$this->assertTrue(true);
}
public function testPrepare()
{
$host = "memory";
$database = $this->getMockBuilder(Concept\Database::class)->getMock();
$database->method('getHost')->willReturn($host);
$database->method('getDsn')->willReturn("sqlite::{$host}");
$database->method('needsUser')->willReturn(false);
$connection = new Connection($database);
$connection = $this->getConnection();
$query = "CREATE TABLE IF NOT EXISTS test_table (id INTEGER PRIMARY KEY, test TEXT)";
$connection->query($query);
$query = "SELECT * FROM test_table";
$result = $connection->prepare($query);
$this->assertInstanceOf(Concept\Database\ResultSet::class, $result);
$connection->prepare($query);
$this->assertTrue(true);
}
}