Added WPDI for mysqli directly
This commit is contained in:
parent
a1717228bc
commit
bea8e57a33
2 changed files with 407 additions and 0 deletions
111
tests/WPDITest.php
Normal file
111
tests/WPDITest.php
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
<?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 WPDOTest extends TestCase {
|
||||
|
||||
public function testConnect()
|
||||
{
|
||||
|
||||
global $pdi;
|
||||
|
||||
$table=new WTable('table_test', ['name', 'last_name', 'type']);
|
||||
|
||||
$pdi=new WPDO($table);
|
||||
|
||||
$this->assertTrue($pdi->connect());
|
||||
|
||||
}
|
||||
|
||||
public function testCreateTable()
|
||||
{
|
||||
global $pdi;
|
||||
|
||||
$sql_table="DROP TABLE IF EXISTS table_test;
|
||||
CREATE TABLE table_test (
|
||||
`name` VARCHAR(255) NOT NULL default '',
|
||||
`last_name` VARCHAR(255) NOT NULL default '',
|
||||
`type` INT NOT NULL
|
||||
);";
|
||||
|
||||
$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);
|
||||
|
||||
$this->assertTrue($pdi->select(['name'], 'WHERE name=? AND type=?', ['first', 1]));
|
||||
|
||||
$arr_result=$pdi->sth->fetchAll();
|
||||
|
||||
$this->assertEquals([['name' => 'first', 0 => 'first']], $arr_result);
|
||||
|
||||
$this->assertEquals([['name' => 'first', 0 => 'first']], $pdi->select_to_array(['name'], 'WHERE name=? AND type=?', ['first', 1]));
|
||||
|
||||
$this->assertEquals(['name' => 'first', 0 => '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']));
|
||||
|
||||
$this->assertTrue($pdi->select(['name'], 'WHERE name=? AND type=?', ['first_updated', 1]));
|
||||
|
||||
$arr_result=$pdi->sth->fetchAll();
|
||||
|
||||
$this->assertEquals([['name' => 'first_updated', 0 => 'first_updated']], $arr_result);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreateTable
|
||||
*/
|
||||
|
||||
public function testDropTable()
|
||||
{
|
||||
global $pdi;
|
||||
|
||||
$this->assertTrue($pdi->query('drop table table_test', []));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue