20250818
This commit is contained in:
121
tests/secret_not_in_git/DatabaseTest.php
Normal file
121
tests/secret_not_in_git/DatabaseTest.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
namespace goodboyalex\php_db_components_pack\tests\secret_not_in_git;
|
||||
|
||||
use Exception;
|
||||
use goodboyalex\php_components_pack\types\GUID;
|
||||
use goodboyalex\php_db_components_pack\classes\ConditionBuilder;
|
||||
use goodboyalex\php_db_components_pack\classes\Database;
|
||||
use goodboyalex\php_db_components_pack\enums\DBDriver;
|
||||
use goodboyalex\php_db_components_pack\models\DBConfig;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class DatabaseTest extends TestCase
|
||||
{
|
||||
public function testGetRow () {}
|
||||
|
||||
public function testInsertMany () {}
|
||||
|
||||
public function testUpdateMany () {}
|
||||
|
||||
public function testExecute () {}
|
||||
|
||||
public function testInsert ()
|
||||
{
|
||||
$this->IncludeReq();
|
||||
|
||||
$db = $this->GetDatabase();
|
||||
|
||||
if (!$db->IsTableExist('users'))
|
||||
die('Таблица не существует. Сперва запустите тест testCreateTable / Table does not exist. Run testCreateTable first');
|
||||
|
||||
if ($db->IsExist(
|
||||
table: 'users',
|
||||
where: new ConditionBuilder()->WhereEquals('login', 'account1')
|
||||
))
|
||||
die('Запись с логином account1 уже существует в таблице users. Сперва удалите запись с логином account1 (можно использовать метод testDelete) / Record with login account1 already exists in table users. Delete record with login account1 first');
|
||||
|
||||
$model = new UserModel(
|
||||
id: GUID::Generate(),
|
||||
login: "account1",
|
||||
password: "password1",
|
||||
salt: GUID_EMPTY,
|
||||
firstName: "firstName1",
|
||||
middleName: "middleName1",
|
||||
lastName: "lastName1",
|
||||
email: "email1@ya.ru",
|
||||
isEmailVerified: false,
|
||||
groupName: "default",
|
||||
createdAt: time(),
|
||||
updatedAt: 0,
|
||||
userData: ['key1' => 'value1', 'key2' => 'value2']
|
||||
);
|
||||
|
||||
$result = $db->Insert('users', $model);
|
||||
|
||||
$this->assertTrue($result !== false);
|
||||
}
|
||||
|
||||
public function testQuery () {}
|
||||
|
||||
public function testQueryLast () {}
|
||||
|
||||
public function testCreateTable ()
|
||||
{
|
||||
$this->IncludeReq();
|
||||
|
||||
$db = $this->GetDatabase();
|
||||
|
||||
$db->CreateTable(
|
||||
tableName: 'users',
|
||||
dbItemClass: '\goodboyalex\php_db_components_pack\tests\secret_not_in_git\UserModel'
|
||||
);
|
||||
|
||||
$this->assertTrue($db->IsTableExist('users'));
|
||||
}
|
||||
|
||||
public function testQueryFirst () {}
|
||||
|
||||
public function testCount () {}
|
||||
|
||||
public function testGetCol () {}
|
||||
|
||||
public function testGetRows () {}
|
||||
|
||||
public function testIsTableExist () {}
|
||||
|
||||
public function testDropTable () {}
|
||||
|
||||
public function testGetValue () {}
|
||||
|
||||
public function testUpdate () {}
|
||||
|
||||
public function testIsExist () {}
|
||||
|
||||
public function testDelete () {}
|
||||
|
||||
private function IncludeReq (): void
|
||||
{
|
||||
require_once 'Converters.php';
|
||||
require_once 'UserModel.php';
|
||||
}
|
||||
|
||||
private function GetDatabase (): Database
|
||||
{
|
||||
$config = new DBConfig(
|
||||
driver: DBDriver::MSSQL,
|
||||
host: '46.172.4.201',
|
||||
port: 17879,
|
||||
name: 'php_db_components_test',
|
||||
userName: "db_user",
|
||||
password: 'hxcssuy:oI.CQ%.zbw=As$Lj7=]+nf'
|
||||
);
|
||||
|
||||
$onException = fn (Exception $exception, bool $terminate)
|
||||
=> $terminate
|
||||
? die($exception->getMessage())
|
||||
: print $exception->getMessage();
|
||||
|
||||
return new Database($config, $onException);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user