Skip to content

Commit

Permalink
test: update test cases #1
Browse files Browse the repository at this point in the history
  • Loading branch information
Chance-fyi committed Oct 21, 2022
1 parent 201085c commit 0a13e45
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
26 changes: 15 additions & 11 deletions test.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,23 @@
$data = [
"name" => rand(0, 100000),
"sex" => rand(0, 1),
"json" => array_rand(range(0, 100), 5),
];
$allData = [
[
"name" => rand(0, 100000),
"sex" => rand(0, 1),
"json" => array_rand(range(0, 100), 5),
],
[
"name" => rand(0, 100000),
"sex" => rand(0, 1),
"json" => array_rand(range(0, 100), 5),
],
[
"name" => rand(0, 100000),
"sex" => rand(0, 1),
"json" => array_rand(range(0, 100), 5),
]
];

Expand All @@ -57,16 +61,16 @@

//-------------DB-------------------
// DB类 新增单条
//Db::name("user")->save($data);
//Db::name("user")->json(["json"])->save($data);

// DB类 新增单条
//Db::name("user")->insert($data);
//Db::name("user")->json(["json"])->insert($data);

// DB类 新增单条 返回id
//Db::name("user")->insertGetId($data);
//Db::name("user")->json(["json"])->insertGetId($data);

// DB类 新增多条
//Db::name("user")->insertAll($allData);
//Db::name("user")->json(["json"])->insertAll($allData);

//-----------------------------------------------------修改------------------------------------------------
//-------------Model----------------
Expand Down Expand Up @@ -95,25 +99,25 @@

//-------------DB-------------------
// 包含主键更新单条
//Db::name("user")->save(["id" => 1] + $data);
//Db::name("user")->json(["json"])->save(["id" => 1] + $data);

// 带条件更新多条
//Db::name("user")->where("id","<", 10)->save($data);
//Db::name("user")->json(["json"])->where("id","<", 10)->save($data);

// 带条件更新单条
//Db::name("user")->where("id","=", 10)->save($data);
//Db::name("user")->json(["json"])->where("id","=", 10)->save($data);

// 带条件更新多条
//Db::name("user")->where("id","<", 10)->update($data);
//Db::name("user")->json(["json"])->where("id","<", 10)->update($data);

// 带条件更新单条
//Db::name("user")->where("id","=", 10)->update($data);
//Db::name("user")->json(["json"])->where("id","=", 10)->update($data);

// 包含主键更新单条
//Db::name("user")->update(["id" => 1] + $data);
//Db::name("user")->json(["json"])->update(["id" => 1] + $data);

// 自增 单条
//Db::name("user")->where("id", 1)->inc("name", 5)->update();
//Db::name("user")->json(["json"])->where("id", 1)->inc("name", 5)->update();

// 自减 多条
//Db::name("user")->where("id", "<", 10)->dec("name", 5)->update();
Expand Down
6 changes: 4 additions & 2 deletions tests/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ protected function createTable()
id int auto_increment
primary key,
name varchar(20) null comment '姓名',
sex tinyint default 0 null comment '性别'
sex tinyint default 0 null comment '性别',
json json null comment 'json'
)
comment '用户';
");
Expand All @@ -116,7 +117,8 @@ protected function createTable()
id int auto_increment
primary key,
name varchar(20) null comment '姓名1',
sex tinyint default 0 null comment '性别1'
sex tinyint default 0 null comment '性别1',
json json null comment 'json1'
)
comment '用户1';
");
Expand Down
4 changes: 2 additions & 2 deletions tests/LogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function testUpdateI($id)
public function testDeleteI($id)
{
IUser::destroy($id);
$this->assertEquals("删除 用户 (id:$id):姓名:Update,性别:0", OperationLog::getLog());
$this->assertEquals("删除 用户 (id:$id):姓名:Update,性别:0,json:", OperationLog::getLog());
}

public function testCreateT()
Expand Down Expand Up @@ -76,6 +76,6 @@ public function testUpdateT($id)
public function testDeleteT($id)
{
TUser::destroy($id);
$this->assertEquals("删除 用户 (id:$id):姓名:Update,性别:女", OperationLog::getLog());
$this->assertEquals("删除 用户 (id:$id):姓名:Update,性别:女,json:", OperationLog::getLog());
}
}
3 changes: 3 additions & 0 deletions tests/model/TUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class TUser extends TBase
"name" => "姓名",
"sex" => "性别",
];
protected $json = [
"json"
];

public function getSexTextAttr($key): string
{
Expand Down

0 comments on commit 0a13e45

Please sign in to comment.