-
Notifications
You must be signed in to change notification settings - Fork 282
Expand file tree
/
Copy pathezQueryTest.php
More file actions
147 lines (118 loc) · 4 KB
/
ezQueryTest.php
File metadata and controls
147 lines (118 loc) · 4 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
namespace ezsql\Tests;
use ezsql\ezQuery;
use ezsql\Tests\EZTestCase;
use function ezsql\functions\{
eq,
neq,
like,
in
};
class ezQueryTest extends EZTestCase
{
protected $object;
protected function setUp(): void
{
$this->object = new ezQuery();
}
protected function tearDown(): void
{
$this->object = null;
}
public function testHaving()
{
$this->assertFalse($this->object->having(''));
$this->assertEmpty($this->object->having());
$expect = $this->object->having(in('other_test', 'testing 1', 'testing 2', 'testing 3', 'testing 4', 'testing 5'));
$this->assertStringContainsString('HAVING', $expect);
}
public function testWhere()
{
$this->assertFalse($this->object->where(''));
$this->assertEmpty($this->object->where());
$expect = $this->object->where(in('where_test', 'testing 1', 'testing 2', 'testing 3', 'testing 4', 'testing 5'));
$this->assertStringContainsString('WHERE', $expect);
$this->assertStringContainsString('IN', $expect);
$this->assertStringContainsString('(', $expect);
$this->assertStringContainsString('testing 2\'', $expect);
$this->assertStringContainsString('testing 5', $expect);
$this->assertStringContainsString(')', $expect);
$this->assertStringContainsString(
'AND',
$this->object->where(
array('where_test', '=', 'testing 1'),
array('test_like', _LIKE, '_good')
)
);
$this->object->prepareOn();
$this->assertStringContainsString('__ez__', $this->object->where(eq('where_test', 'testing 1')));
$this->assertFalse($this->object->where(like('where_test', 'fail')));
}
public function testPrepareOn()
{
$this->object->prepareOn();
$expect = $this->object->where(
['where_test', _IN, 'testing 1', 'testing 2', 'testing 3', 'testing 4', 'testing 5']
);
$this->assertEquals(5, preg_match_all('/__ez__/', $expect));
}
public function testPrepareOff()
{
$this->object->prepareOff();
$this->assertFalse(
$this->object->where(
array('where_test', '=', 'testing 1', 'or'),
array('test_like', 'LIKE', ':bad')
)
);
}
public function testAddPrepare()
{
$this->object->prepareOn();
$expect = $this->object->where(
eq('where_test', 'testing 1'),
neq('some_key', 'other', _OR),
like('other_key', '%any')
);
$this->assertEquals(3, preg_match_all('/__ez__/', $expect));
}
public function testDelete()
{
$this->assertFalse($this->object->delete(''));
$this->assertFalse($this->object->delete('test_unit_delete', array('good', 'bad')));
}
public function testSelect()
{
$this->assertFalse($this->object->select('', ''));
$this->assertNotNull($this->object->select('table', 'columns', 'WHERE', 'GROUP BY', 'HAVING', 'ORDER BY', 'LIMIT'));
}
public function testCreate_select()
{
$this->assertFalse($this->object->create_select('', '', ''));
}
public function testInsert_select()
{
$this->assertFalse($this->object->insert_select('', '', ''));
}
public function testInsert()
{
$this->assertFalse($this->object->insert('', ''));
}
public function testUpdate()
{
$this->assertFalse($this->object->update('', ''));
$this->assertFalse($this->object->update('test_unit_delete', array('test_unit_update' => 'date()'), ''));
}
public function testReplace()
{
$this->assertFalse($this->object->replace('', ''));
}
public function test__Construct()
{
$ezQuery = $this->getMockBuilder(ezQuery::class)
->setMethods(null)
->disableOriginalConstructor()
->getMock();
$this->assertNull($ezQuery->__construct());
}
}