125 lines
3.2 KiB
PHP
125 lines
3.2 KiB
PHP
<?php
|
|
|
|
use PhangoApp\WPDO\WPDI;
|
|
use PhangoApp\WPDO\WTable;
|
|
use PhangoApp\PhaUtils\Utils;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
include("vendor/autoload.php");
|
|
include("libraries/Utils.php");
|
|
|
|
Utils::load_config('config_test', 'settings');
|
|
|
|
final class WPDITest extends TestCase {
|
|
|
|
public function testConnect()
|
|
{
|
|
|
|
global $pdi;
|
|
|
|
$table=new WTable('table_test', ['name', 'last_name', 'type']);
|
|
|
|
$pdi=new WPDI($table);
|
|
|
|
$this->assertTrue($pdi->connect());
|
|
|
|
}
|
|
|
|
public function testCreateTable()
|
|
{
|
|
global $pdi;
|
|
|
|
/*CREATE TABLE MyGuests (
|
|
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
firstname VARCHAR(30) NOT NULL,
|
|
lastname VARCHAR(30) NOT NULL,
|
|
email VARCHAR(50),
|
|
reg_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
|
)*/
|
|
|
|
//$sql_table="DROP TABLE IF EXISTS table_test;CREATE TABLE table_test ( id INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY, name VARCHAR(30) NOT NULL, last_name VARCHAR(30) NOT NULL, type INT NOT NULL )";
|
|
|
|
$sql_table="DROP TABLE IF EXISTS table_test;";
|
|
|
|
$this->assertTrue($pdi->query($sql_table, []));
|
|
|
|
$sql_table="CREATE TABLE table_test ( \n".
|
|
"id INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,\n".
|
|
"name VARCHAR(30) NOT NULL,\n".
|
|
"last_name VARCHAR(30) NOT NULL,\n".
|
|
"type INT NOT NULL\n".
|
|
" )";
|
|
|
|
$this->assertTrue($pdi->query($sql_table, []));
|
|
|
|
}
|
|
|
|
/**
|
|
* @depends testCreateTable
|
|
*/
|
|
|
|
public function testInsert() {
|
|
|
|
global $pdi;
|
|
|
|
$this->assertEquals('table_test', $pdi->table->name);
|
|
|
|
$this->assertTrue($pdi->insert(['name' => 'first', 'last_name' => 'last', 'type' => 1]));
|
|
|
|
}
|
|
|
|
/**
|
|
* @depends testInsert
|
|
*/
|
|
|
|
public function testSelect() {
|
|
|
|
global $pdi;
|
|
|
|
$this->assertEquals('table_test', $pdi->table->name);
|
|
|
|
$result=$pdi->select(['name'], 'WHERE name=? AND type=?', ['first', 1]);
|
|
|
|
$arr_result=$result->fetch_all(MYSQLI_ASSOC);
|
|
|
|
$this->assertEquals([['name' => 'first']], $arr_result);
|
|
|
|
$this->assertEquals([['name' => 'first']], $pdi->select_to_array(['name'], 'WHERE name=? AND type=?', ['first', 1]));
|
|
|
|
$this->assertEquals(['name' => 'first'], $pdi->select_a_row(['name'], 'WHERE name=? AND type=?', ['first', 1]));
|
|
|
|
$this->assertEquals(1, $pdi->select_count('WHERE name=?', ['first']));
|
|
|
|
}
|
|
|
|
/**
|
|
* @depends testInsert
|
|
*/
|
|
|
|
public function testUpdate() {
|
|
|
|
global $pdi;
|
|
|
|
$this->assertTrue($pdi->update(['name'], ['first_updated'], 'WHERE name=?', ['first']));
|
|
|
|
$result=$pdi->select(['name'], 'WHERE name=? AND type=?', ['first_updated', 1]);
|
|
|
|
$arr_result=$result->fetch_all(MYSQLI_ASSOC);
|
|
|
|
$this->assertEquals([['name' => 'first_updated']], $arr_result);
|
|
|
|
}
|
|
|
|
/**
|
|
* @depends testCreateTable
|
|
*/
|
|
|
|
public function testDropTable()
|
|
{
|
|
global $pdi;
|
|
|
|
$this->assertTrue($pdi->query('drop table table_test', []));
|
|
|
|
}
|
|
|
|
}
|