Added testing
This commit is contained in:
65
tests/ConnectionTest.php
Normal file
65
tests/ConnectionTest.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
use ProVM\Database\Connection;
|
||||
use ProVM\Concept;
|
||||
|
||||
class ConnectionTest extends TestCase
|
||||
{
|
||||
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->query($query);
|
||||
}
|
||||
protected function tearDown(): void
|
||||
{
|
||||
unset($this->pdo);
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
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);
|
||||
$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);
|
||||
}
|
||||
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);
|
||||
$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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user