-
Notifications
You must be signed in to change notification settings - Fork 282
Expand file tree
/
Copy pathezsqlModelTest.php
More file actions
258 lines (214 loc) · 7.61 KB
/
ezsqlModelTest.php
File metadata and controls
258 lines (214 loc) · 7.61 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
<?php
namespace ezsql\Tests;
use ezsql\ezsqlModel;
use ezsql\Tests\EZTestCase;
class ezsqlModelTest extends EZTestCase
{
/**
* @var ezsqlModel
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp(): void
{
$this->object = new ezsqlModel();
}
public function testGet_host_port()
{
$hostPort = $this->object->get_host_port("localhost:8181");
$this->assertEquals($hostPort[0], "localhost");
$this->assertEquals($hostPort[1], "8181");
}
public function testGetCache_Timeout()
{
$res = $this->object->getCacheTimeout();
$this->assertEquals(24, $res);
}
public function testSetCache_Timeout()
{
$this->object->setCache_Timeout(44);
$this->assertEquals(44, $this->object->getCache_Timeout());
}
public function testGetNotProperty()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessageRegExp('/does not exist/');
$res = $this->object->getNotProperty();
}
public function testRegister_error()
{
$err_str = 'Test error string';
$this->object->hide_errors();
$this->object->register_error($err_str);
$this->assertEquals($err_str, $this->object->getLast_Error());
$this->object->show_errors();
set_error_handler([$this, 'errorHandler']);
$this->assertFalse($this->object->register_error($err_str));
$this->object->hide_errors();
}
public function testShow_errors()
{
$this->object->hide_errors();
$this->assertFalse($this->object->getShow_Errors());
$this->object->show_errors();
$this->assertTrue($this->object->getShow_Errors());
}
public function testHide_errors()
{
$this->object->hide_errors();
$this->assertFalse($this->object->getShow_Errors());
}
public function testFlush()
{
$this->object->flush();
$this->assertNull($this->object->getLast_Result());
$this->assertNull($this->object->getLast_Query());
$this->assertEquals([], $this->object->getCol_Info());
$this->assertFalse($this->object->getFrom_Disk_Cache());
}
public function testGet_var()
{
$this->assertEmpty($this->object->get_var());
$this->object->setLast_Result([new \stdClass]);
$this->assertNull($this->object->get_var());
$this->assertNull($this->object->get_var('1'));
}
public function testGet_row()
{
$this->assertNull($this->object->get_row());
$this->assertNull($this->object->get_row(null, ARRAY_A));
$this->assertNull($this->object->get_row(null, ARRAY_N));
$this->object->hide_errors();
$this->assertNull($this->object->get_row(null, 'BAD'));
$this->assertNull($this->object->get_row('1'));
}
public function testGet_col()
{
$this->assertEmpty($this->object->get_col());
$this->object->setLast_Result([new \stdClass]);
$this->assertNotNull($this->object->get_col());
$this->assertNotFalse($this->object->get_col('1'));
}
public function testGet_results()
{
$this->assertNull($this->object->get_results());
$this->assertNotNull($this->object->get_results(null, ARRAY_A));
$this->assertNull($this->object->get_results('1'));
}
public function testGet_col_info()
{
$this->assertEmpty($this->object->get_col_info());
$this->object->setColInfo([]);
$this->assertNull($this->object->get_col_info());
$this->assertNull($this->object->get_col_info('name', 1));
}
public function testStore_cache()
{
$sql = 'SELECT * FROM ez_test';
$this->object->setCacheTimeout(1);
$this->object->setUseDiskCache(true);
$this->object->setCacheQueries(true);
$this->object->setNumRows(5);
$this->object->store_cache($sql, false);
$this->assertEquals(5, $this->object->get_cache($sql));
}
public function testGet_cache()
{
$sql = 'SELECT * FROM ez_test';
$this->object->setCache_Timeout(1);
$this->object->setUse_Disk_Cache(true);
$this->object->setCache_Queries(true);
$this->object->setNum_Rows(2);
$this->object->store_cache($sql, false);
$this->assertEquals(2, $this->object->get_cache($sql));
}
/**
* The test does not echos HTML, it is just a test, that is still running
*/
public function testVarDump()
{
$this->object->debugOff();
$this->object->setLastResult(['test 1']);
$this->assertNotEmpty($this->object->varDump($this->object->getLast_Result()));
$this->object->debugOn();
$this->expectOutputRegex('/[Last Function Call]/');
$this->object->varDump('');
}
public function testDump_var()
{
$this->object->setDebugEchoIsOn(true);
$this->object->setLastResult(['Test 1', 'Test 2']);
$this->expectOutputRegex('/[Last Function Call]/');
$this->object->dump_var();
}
public function testDebug()
{
$this->object->setDebug_Echo_Is_On(true);
$this->assertNotEmpty($this->object->debug(false));
// In addition of getting a result, it fills the console
$this->object->setLastError("test last");
$this->expectOutputRegex('/[test last]/');
$this->object->debug();
$this->object->setFromDiskCache(true);
$this->expectOutputRegex('/[Results retrieved from disk cache]/');
$this->object->debug();
$this->object->setColInfo(["just another test"]);
$this->object->debug(false);
$this->object->setColInfo(null);
$this->object->setLast_Result(["just another test II"]);
$this->object->debug(false);
}
public function testTimer_get_cur()
{
list($usec, $sec) = explode(' ', microtime());
$expected = ((float) $usec + (float) $sec);
$this->assertGreaterThanOrEqual($expected, $this->object->timer_get_cur());
}
public function testTimer_start()
{
$this->object->timer_start('test_timer');
$this->assertNotNull($this->object->getTimers());
}
public function testTimer_elapsed()
{
$expected = 0;
$this->object->timer_start('test_timer');
usleep(5);
$this->assertGreaterThanOrEqual($expected, $this->object->timer_elapsed('test_timer'));
}
public function testTimer_update_global()
{
$this->object->timer_start('test_timer');
usleep(5);
$this->object->setDoProfile(true);
$this->object->timer_update_global('test_timer');
$expected = $this->object->getTotalQueryTime();
$this->assertGreaterThanOrEqual($expected, $this->object->timer_elapsed('test_timer'));
}
public function testCount()
{
$this->assertEquals(0, $this->object->count());
$this->object->count(true, true);
$this->assertEquals(1, $this->object->count());
$this->assertEquals(2, $this->object->count(false, true));
}
public function testAffectedRows()
{
$this->assertEquals(0, $this->object->affectedRows());
}
public function testIsConnected()
{
$this->assertFalse($this->object->isConnected());
}
public function test__Construct()
{
$ezsqlModel = $this->getMockBuilder(ezsqlModel::class)
->setMethods(null)
->disableOriginalConstructor()
->getMock();
$this->assertNull($ezsqlModel->__construct());
}
}