-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathUpdateTest.php
38 lines (28 loc) · 1.09 KB
/
UpdateTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class UpdateTest extends TestCase
{
public function test(): void
{
$db = db();
$db->table('users')->where('id = ?', 1)->update('name', 'foo1')->rowCount();
$data = [
'name' => 'foo2',
'balance' => 100,
];
$db->table('users')->where('id = ?', 1)->updates($data);
$data = [
'balance' => new Mix\Database\Expr('balance + ?', 1),
];
$db->table('users')->where('id = ?', 1)->updates($data);
$db->table('users')->where('id = ?', 1)->update('balance', new Mix\Database\Expr('balance + ?', 1));
$rowsAffected = $db->table('users')->where('id = ?', 1)->update('add_time', new Mix\Database\Expr('CURRENT_TIMESTAMP()'))->rowCount();
$this->assertEquals(1, $rowsAffected);
$data = [
'add_time' => new Mix\Database\Expr('CURRENT_TIMESTAMP()'),
];
$rowsAffected = $db->table('users')->where('id = ?', 1)->updates($data)->rowCount();
$this->assertEquals(0, $rowsAffected);
}
}