单元测试改进

This commit is contained in:
thinkphp
2017-01-31 16:20:37 +08:00
parent 1d23f67e11
commit 509905bbe4

View File

@@ -195,7 +195,7 @@ EOF;
'username' => 'chunice',
'password' => md5('chunice'),
'status' => 1,
'create_time' => time()
'create_time' => time(),
];
$result = Db::connect($config)->name('user')->insert($data);
$this->assertEquals(1, $result);
@@ -208,7 +208,7 @@ EOF;
'username' => 'chunice_update',
'password' => md5('chunice'),
'status' => 1,
'create_time' => time()
'create_time' => time(),
];
$result = Db::connect($config)->name('user')->where('username', 'chunice')->update($data);
$this->assertEquals(1, $result);
@@ -229,7 +229,7 @@ EOF;
$data = [
['username' => 'foo', 'password' => md5('foo'), 'status' => 1, 'create_time' => time()],
['username' => 'bar', 'password' => md5('bar'), 'status' => 1, 'create_time' => time()]
['username' => 'bar', 'password' => md5('bar'), 'status' => 1, 'create_time' => time()],
];
$insertNum = Db::connect($config)->name('user')->insertAll($data);
@@ -273,7 +273,7 @@ EOF;
'username' => uniqid(),
'password' => md5('chunice'),
'status' => 1,
'create_time' => time()
'create_time' => time(),
];
$lastId = Db::connect($config)->name('user')->insertGetId($data);
$this->assertEquals($id + 1, $lastId);
@@ -287,7 +287,7 @@ EOF;
'username' => uniqid(),
'password' => md5('chunice'),
'status' => 1,
'create_time' => time()
'create_time' => time(),
];
$lastId = Db::connect($config)->name('user')->insertGetId($data);
@@ -341,12 +341,12 @@ EOF;
public function testCache()
{
$config = $this->getConfig();
$result = Db::connect($config)->name('user')->where('id', 1)->cache('key', 60)->select();
$result = Db::connect($config)->name('user')->where('id', 1)->cache('key', 60)->find();
$cache = \think\Cache::get('key');
$this->assertEquals($result, $cache);
$updateCache = Db::connect($config)->name('user')->cache('key')->find(2);
$this->assertNotEquals($cache, $updateCache);
$updateCache = Db::connect($config)->name('user')->cache('key')->find(1);
$this->assertEquals($cache, $updateCache);
}
}