-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathUpdateTest.php
More file actions
74 lines (57 loc) · 2.06 KB
/
UpdateTest.php
File metadata and controls
74 lines (57 loc) · 2.06 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
namespace ipl\Tests\Sql;
use ipl\Sql\Expression;
use ipl\Sql\Select;
use ipl\Sql\Test\TestCase;
use ipl\Sql\Update;
class UpdateTest extends TestCase
{
protected string $queryClass = Update::class;
/** @var Update */
protected $query;
public function testEmptyUpdateTable()
{
$this->assertSame(null, $this->query->getTable());
$this->assertSame([], $this->query->getSet());
$this->assertSql('', $this->query, []);
}
public function testTableSpecification()
{
$this->query->table('table');
$this->assertSame(['table'], $this->query->getTable());
$this->assertSql('UPDATE table', $this->query, []);
}
public function testTableSpecificationWithSchema()
{
$this->query->table('schema.table');
$this->assertSame(['schema.table'], $this->query->getTable());
$this->assertSql('UPDATE schema.table', $this->query, []);
}
public function testSet()
{
$this->query->set(['c1' => 'v1', 'c2' => 'v2']);
$this->assertSame(['c1' => 'v1', 'c2' => 'v2'], $this->query->getSet());
$this->assertSql('SET c1 = ?, c2 = ?', $this->query, ['v1', 'v2']);
}
public function testExpressionValue()
{
$value = new Expression('x = ?', null, 1);
$this->query->set(['c1' => $value]);
$this->assertSame(['c1' => $value], $this->query->getSet());
$this->assertSql('SET c1 = x = ?', $this->query, [1]);
}
public function testSelectValue()
{
$value = (new Select())->columns('COUNT(*)')->from('table2')->where(['active = ?' => 1]);
$this->query->set(['c1' => $value]);
$this->assertSame(['c1' => $value], $this->query->getSet());
$this->assertSql('SET c1 = (SELECT COUNT(*) FROM table2 WHERE active = ?)', $this->query, [1]);
}
public function testUpdateStatementWithSet()
{
$this->query
->table('table')
->set(['c1' => 'v1', 'c2' => 'v2']);
$this->assertSql('UPDATE table SET c1 = ?, c2 = ?', $this->query, ['v1', 'v2']);
}
}