-
-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathSelection.havingOr().phpt
More file actions
106 lines (84 loc) · 2.25 KB
/
Selection.havingOr().phpt
File metadata and controls
106 lines (84 loc) · 2.25 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
/**
* Test: Nette\Database\Table: HavingOr operations
* @dataProvider? ../databases.ini
*/
declare(strict_types=1);
use Tester\Assert;
require __DIR__ . '/../connect.inc.php'; // create $connection
Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql");
// without question mark
test(function () use ($context) {
$count = $context->table('book')->havingOr([
'author_id' => 12,
'title' => 'JUSH',
])->count();
Assert::same(3, $count);
});
// full condition
test(function () use ($context) {
$count = $context->table('book')->havingOr([
'translator_id IS NULL',
'title' => 'Dibi',
])->count();
Assert::same(2, $count);
});
// with question mark
test(function () use ($context) {
$count = $context->table('book')->havingOr([
'id > ?' => 3,
'translator_id' => 11,
])->count();
Assert::same(2, $count);
});
// just one condition
test(function () use ($context) {
$count = $context->table('book')->havingOr([
'id > ?' => 3,
])->count();
Assert::same(1, $count);
});
// with question mark
test(function () use ($context) {
$count = $context->table('book')->havingOr([
'id ?' => [3, 4],
'translator_id' => 11,
])->count();
Assert::same(3, $count);
});
// multiple values for one key
test(function () use ($context) {
$count = $context->table('author')->havingOr([
'id > ?' => 12,
'ROUND(id, ?) = ?' => [5, 3],
])->count();
Assert::same(1, $count);
});
// nested condition
test(function () use ($context) {
$books = $context->table('book')->havingOr([
'id = ?' => 4,
'author_id = ? AND translator_id ?' => [11, null],
]);
Assert::same(2, $books->count());
});
// invalid param count
test(function () use ($context) {
$f = function () use ($context) {
$context->table('author')->havingOr([
'id > ?' => 3,
'ROUND(id, ?) = ?' => [5],
])->count();
};
Assert::throws($f, Nette\InvalidArgumentException::class, 'Argument count does not match placeholder count.');
});
// invalid param count
test(function () use ($context) {
$f = function () use ($context) {
$context->table('author')->havingOr([
'id > ?' => 3,
'ROUND(id, ?) = ?' => 5,
])->count();
};
Assert::throws($f, Nette\InvalidArgumentException::class, 'Argument count does not match placeholder count.');
});