-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathInsertQueryTest.php
More file actions
60 lines (50 loc) · 1.93 KB
/
Copy pathInsertQueryTest.php
File metadata and controls
60 lines (50 loc) · 1.93 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
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
require_once "..".DIRECTORY_SEPARATOR."autoload.php";
require_once 'PHPUnit/Framework.php';
class InsertQueryTest extends PHPUnit_Framework_TestCase
{
public function testBasic()
{
$q = new InsertQuery(array('test'));
$q->setValues(array(
'field1' => 'value1',
'field2' => 'value2'
));
$this->assertEquals('INSERT INTO `test` (`field1`, `field2`) VALUES (:p1, :p2)', $q->sql());
$params = $q->parameters();
$this->assertEquals('value1', $params[':p1']);
$this->assertEquals('value2', $params[':p2']);
// shorthand
$q = new InsertQuery('test');
$q->field1 = 'value1';
$q->field2 = 'value2';
$this->assertEquals('INSERT INTO `test` (`field1`, `field2`) VALUES (:p1, :p2)', $q->sql());
$params = $q->parameters();
$this->assertEquals('value1', $params[':p1']);
$this->assertEquals('value2', $params[':p2']);
}
public function testMultitable()
{
try {
$q = new InsertQuery(array('test', 'test2'));
$this->assertEquals(true, false);
} catch (InvalidArgumentException $e) {
}
}
public function testOnDuplicate()
{
$q = new InsertQuery(array('test'), true);
$q->setValues(array(
'id' => '35',
'field1' => 'value1',
'field2' => 'value2'
));
$this->assertEquals('INSERT INTO `test` (`id`, `field1`, `field2`) VALUES (:p1, :p2, :p3) ON DUPLICATE KEY UPDATE `id` = LAST_INSERT_ID(`id`), `field1` = VALUES(`field1`), `field2` = VALUES(`field2`)', $q->sql());
$params = $q->parameters();
$this->assertEquals('35', $params[':p1']);
$this->assertEquals('value1', $params[':p2']);
$this->assertEquals('value2', $params[':p3']);
$this->assertEquals(3, count($params));
}
}