Skip to content

Commit 6ece68e

Browse files
committed
Updated phpUnit Tests
To include `leftJoin()` phpunit testing and also fix a couple of phpunit depreciation warnings.
1 parent 52af9bd commit 6ece68e

File tree

7 files changed

+187
-40
lines changed

7 files changed

+187
-40
lines changed

tests/ezFunctionsTest.php

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class ezFunctionsTest extends EZTestCase
88
{
99
protected function setUp(): void
10-
{
10+
{
1111
\clearInstance();
1212
}
1313

@@ -58,146 +58,159 @@ public function testDropColumn()
5858

5959
public function testEq()
6060
{
61-
$this->assertInternalType('array', eq('field', 'data'));
61+
$this->assertIsArray(eq('field', 'data'));
6262
$this->assertArraySubset([1 => EQ], eq('field', 'data'));
6363
}
6464

6565
public function testNeq()
6666
{
67-
$this->assertInternalType('array', neq('field', 'data'));
67+
$this->assertIsArray(neq('field', 'data'));
6868
$this->assertArraySubset([3 => _AND], neq('field', 'data', _AND));
6969
}
7070

7171
public function testNe()
7272
{
73-
$this->assertInternalType('array', ne('field', 'data'));
73+
$this->assertIsArray(ne('field', 'data'));
7474
$this->assertArraySubset([4 => 'extra'], ne('field', 'data', _AND, 'extra'));
7575
}
7676

7777
public function testLt()
7878
{
79-
$this->assertInternalType('array', lt('field', 'data'));
79+
$this->assertIsArray(lt('field', 'data'));
8080
$this->assertArraySubset([2 => 'data'], lt('field', 'data'));
8181
}
8282

8383
public function testLte()
8484
{
85-
$this->assertInternalType('array', lte('field', 'data'));
85+
$this->assertIsArray(lte('field', 'data'));
8686
$this->assertArraySubset([0 => 'field'], lte('field', 'data'));
8787
}
8888

8989
public function testGt()
9090
{
91-
$this->assertInternalType('array', gt('field', 'data'));
91+
$this->assertIsArray(gt('field', 'data'));
9292
$this->assertArraySubset([0 => 'field'], gt('field', 'data'));
9393
}
9494

9595
public function testGte()
9696
{
97-
$this->assertInternalType('array', gte('field', 'data'));
97+
$this->assertIsArray(gte('field', 'data'));
9898
$this->assertArraySubset([0 => 'field'], gte('field', 'data'));
9999
}
100100

101101
public function testIsNull()
102102
{
103-
$this->assertInternalType('array', isNull('field'));
103+
$this->assertIsArray(isNull('field'));
104104
$this->assertArraySubset([2 => 'null'], isNull('field'));
105105
}
106106

107107
public function testIsNotNull()
108108
{
109-
$this->assertInternalType('array', isNotNull('field'));
109+
$this->assertIsArray(isNotNull('field'));
110110
$this->assertArraySubset([2 => 'null'], isNotNull('field'));
111111
}
112112

113113
public function testLike()
114114
{
115-
$this->assertInternalType('array', like('field', 'data'));
115+
$this->assertIsArray(like('field', 'data'));
116116
$this->assertArraySubset([2 => 'data'], like('field', 'data'));
117117
}
118118

119119
public function testNotLike()
120120
{
121-
$this->assertInternalType('array', notLike('field', 'data'));
121+
$this->assertIsArray(notLike('field', 'data'));
122122
$this->assertArraySubset([2 => 'data'], notLike('field', 'data'));
123123
}
124124

125125
public function testIn()
126126
{
127-
$this->assertInternalType('array', in('field', 'data'));
127+
$this->assertIsArray(in('field', 'data'));
128128
$this->assertArraySubset([8 => 'data6'], in('field', 'data', 'data1', 'data2', 'data3', 'data4', 'data5', 'data6'));
129129
}
130130

131131
public function testNotIn()
132132
{
133-
$this->assertInternalType('array', notIn('field', 'data'));
133+
$this->assertIsArray(notIn('field', 'data'));
134134
$this->assertArraySubset([5 => 'data3'], notIn('field', 'data', 'data1', 'data2', 'data3', 'data4', 'data5', 'data6'));
135135
}
136136

137137
public function testBetween()
138138
{
139-
$this->assertInternalType('array', between('field', 'data', 'data2'));
139+
$this->assertIsArray(between('field', 'data', 'data2'));
140140
$this->assertArraySubset([1 => _BETWEEN], between('field', 'data', 'data2'));
141141
}
142142

143143
public function testNotBetween()
144144
{
145-
$this->assertInternalType('array', notBetween('field', 'data', 'data2'));
145+
$this->assertIsArray(notBetween('field', 'data', 'data2'));
146146
$this->assertArraySubset([3 => 'data2'], notBetween('field', 'data', 'data2'));
147147
}
148148

149-
public function testSetInstance() {
149+
public function testSetInstance()
150+
{
150151
$this->assertFalse(\setInstance());
151152
$this->assertFalse(\setInstance($this));
152153
}
153154

154-
public function testSelect() {
155+
public function testSelect()
156+
{
155157
$this->assertFalse(select(''));
156158
}
157159

158-
public function testSelect_into() {
160+
public function testSelect_into()
161+
{
159162
$this->assertFalse(select_into('field', 'data', 'data2'));
160163
}
161164

162-
public function testInsert_select() {
165+
public function testInsert_select()
166+
{
163167
$this->assertFalse(insert_select('field', 'data', 'data2'));
164168
}
165169

166-
public function testCreate_select() {
170+
public function testCreate_select()
171+
{
167172
$this->assertFalse(create_select('field', 'data', 'data2'));
168173
}
169174

170-
public function testWhere() {
175+
public function testWhere()
176+
{
171177
$this->assertFalse(where('field', 'data', 'data2'));
172178
}
173179

174-
public function testGroupBy() {
180+
public function testGroupBy()
181+
{
175182
$this->assertFalse(groupBy(''));
176183
$this->assertNotNull(groupBy('field'));
177184
}
178185

179-
public function testHaving() {
186+
public function testHaving()
187+
{
180188
$this->assertFalse(having('field', 'data', 'data2'));
181189
}
182190

183-
public function testOrderBy() {
191+
public function testOrderBy()
192+
{
184193
$this->assertFalse(orderBy('', 'data'));
185194
$this->assertNotNull(orderBy('field', 'data'));
186195
}
187196

188-
public function testInsert() {
197+
public function testInsert()
198+
{
189199
$this->assertFalse(insert('field', ['data' => 'data2']));
190200
}
191201

192-
public function testUpdate() {
202+
public function testUpdate()
203+
{
193204
$this->assertFalse(update('field', 'data', 'data2'));
194205
}
195206

196-
public function testDeleting() {
207+
public function testDeleting()
208+
{
197209
$this->assertFalse(deleting('field', 'data', 'data2'));
198210
}
199211

200-
public function testReplace() {
212+
public function testReplace()
213+
{
201214
$this->assertFalse(replace('field', ['data' => 'data2']));
202215
}
203216
}

tests/ezQueryTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function testHaving()
3131

3232
$expect = $this->object->having(in('other_test', 'testing 1', 'testing 2', 'testing 3', 'testing 4', 'testing 5'));
3333

34-
$this->assertContains('HAVING', $expect);
34+
$this->assertStringContainsString('HAVING', $expect);
3535
}
3636

3737
public function testWhere()
@@ -41,14 +41,14 @@ public function testWhere()
4141

4242
$expect = $this->object->where(in('where_test', 'testing 1', 'testing 2', 'testing 3', 'testing 4', 'testing 5'));
4343

44-
$this->assertContains('WHERE', $expect);
45-
$this->assertContains('IN', $expect);
46-
$this->assertContains('(', $expect);
47-
$this->assertContains('testing 2\'', $expect);
48-
$this->assertContains('testing 5', $expect);
49-
$this->assertContains(')', $expect);
44+
$this->assertStringContainsString('WHERE', $expect);
45+
$this->assertStringContainsString('IN', $expect);
46+
$this->assertStringContainsString('(', $expect);
47+
$this->assertStringContainsString('testing 2\'', $expect);
48+
$this->assertStringContainsString('testing 5', $expect);
49+
$this->assertStringContainsString(')', $expect);
5050

51-
$this->assertContains(
51+
$this->assertStringContainsString(
5252
'AND',
5353
$this->object->where(
5454
array('where_test', '=', 'testing 1'),
@@ -57,7 +57,7 @@ public function testWhere()
5757
);
5858

5959
$this->object->prepareOn();
60-
$this->assertContains('__ez__', $this->object->where(eq('where_test', 'testing 1')));
60+
$this->assertStringContainsString('__ez__', $this->object->where(eq('where_test', 'testing 1')));
6161
$this->assertFalse($this->object->where(like('where_test', 'fail')));
6262
}
6363

tests/mysqli/mysqliTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ public function testWhere()
545545
)
546546
);
547547

548-
$this->assertContains('WHERE where_test BETWEEN \'testing 1\' AND \'testing 2\' AND test_null IS NULL', $expect);
548+
$this->assertStringContainsString('WHERE where_test BETWEEN \'testing 1\' AND \'testing 2\' AND test_null IS NULL', $expect);
549549

550550
$this->assertFalse(where(
551551
array('where_test', 'bad', 'testing 1', 'or'),
@@ -558,7 +558,7 @@ public function testWhere()
558558
like('test_null', 'null')
559559
);
560560

561-
$this->assertContains('WHERE where_test BETWEEN ' . _TAG . ' AND ' . _TAG . ' AND test_null IS NULL', $expect);
561+
$this->assertStringContainsString('WHERE where_test BETWEEN ' . _TAG . ' AND ' . _TAG . ' AND test_null IS NULL', $expect);
562562
}
563563

564564
public function testQuery_prepared()

tests/pdo/pdo_mysqlTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,41 @@ public function testSelecting()
265265
$this->assertEquals(0, $this->object->query('DROP TABLE unit_test'));
266266
}
267267

268+
public function testJoins()
269+
{
270+
$this->assertTrue($this->object->connect('mysql:host=' . self::TEST_DB_HOST . ';dbname=' . self::TEST_DB_NAME . ';port=' . self::TEST_DB_PORT, self::TEST_DB_USER, self::TEST_DB_PASSWORD));
271+
$this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), PRIMARY KEY (ID))');
272+
$this->object->insert('unit_test', array('id' => '1', 'test_key' => 'testing 1'));
273+
$this->object->insert('unit_test', array('id' => '2', 'test_key' => 'testing 2'));
274+
$this->object->insert('unit_test', array('id' => '3', 'test_key' => 'testing 3'));
275+
$this->object->query('CREATE TABLE unit_test_child(child_id integer, child_test_key varchar(50), parent_id integer, PRIMARY KEY (child_id))');
276+
$this->object->insert('unit_test', array('child_id' => '1', 'child_test_key' => 'testing child 1', 'parent_id' => '3'));
277+
$this->object->insert('unit_test', array('child_id' => '2', 'child_test_key' => 'testing child 2', 'parent_id' => '2'));
278+
$this->object->insert('unit_test', array('child_id' => '3', 'child_test_key' => 'testing child 3', 'parent_id' => '1'));
279+
280+
$result = $this->object->selecting('unit_test_child', '*', leftJoin('unit_test_child', 'unit_test', 'parent_id', 'id'));
281+
$i = 1;
282+
$o = 3;
283+
foreach ($result as $row) {
284+
$this->assertEquals($i, $row->child_id);
285+
$this->assertEquals('testing child ' . $i, $row->child_test_key);
286+
$this->assertEquals($o, $row->id);
287+
$this->assertEquals('testing ' . $o, $row->test_key);
288+
++$i;
289+
--$o;
290+
}
291+
292+
$result = $this->object->selecting('unit_test_child', 'child.parent_id', leftJoin('unit_test_child', 'unit_test', 'parent_id', 'id', 'child'));
293+
$o = 3;
294+
foreach ($result as $row) {
295+
$this->assertEquals($o, $row->parent_id);
296+
--$o;
297+
}
298+
299+
$this->assertEquals(0, $this->object->query('DROP TABLE unit_test'));
300+
$this->assertEquals(0, $this->object->query('DROP TABLE unit_test_child'));
301+
}
302+
268303
public function testBeginTransactionCommit()
269304
{
270305
$this->object->connect();

tests/pdo/pdo_pgsqlTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,38 @@ public function testSelecting()
189189
}
190190
}
191191

192+
public function testJoins()
193+
{
194+
$this->assertTrue($this->object->connect('pgsql:host=' . self::TEST_DB_HOST . ';dbname=' . self::TEST_DB_NAME . ';port=' . self::TEST_DB_PORT, self::TEST_DB_USER, self::TEST_DB_PASSWORD));
195+
$this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), PRIMARY KEY (ID))');
196+
$this->object->insert('unit_test', array('id' => '1', 'test_key' => 'testing 1'));
197+
$this->object->insert('unit_test', array('id' => '2', 'test_key' => 'testing 2'));
198+
$this->object->insert('unit_test', array('id' => '3', 'test_key' => 'testing 3'));
199+
$this->object->query('CREATE TABLE unit_test_child(child_id integer, child_test_key varchar(50), parent_id integer, PRIMARY KEY (child_id))');
200+
$this->object->insert('unit_test', array('child_id' => '1', 'child_test_key' => 'testing child 1', 'parent_id' => '3'));
201+
$this->object->insert('unit_test', array('child_id' => '2', 'child_test_key' => 'testing child 2', 'parent_id' => '2'));
202+
$this->object->insert('unit_test', array('child_id' => '3', 'child_test_key' => 'testing child 3', 'parent_id' => '1'));
203+
204+
$result = $this->object->selecting('unit_test_child', '*', leftJoin('unit_test_child', 'unit_test', 'parent_id', 'id'));
205+
$i = 1;
206+
$o = 3;
207+
foreach ($result as $row) {
208+
$this->assertEquals($i, $row->child_id);
209+
$this->assertEquals('testing child ' . $i, $row->child_test_key);
210+
$this->assertEquals($o, $row->id);
211+
$this->assertEquals('testing ' . $o, $row->test_key);
212+
++$i;
213+
--$o;
214+
}
215+
216+
$result = $this->object->selecting('unit_test_child', 'child.parent_id', leftJoin('unit_test_child', 'unit_test', 'parent_id', 'id', 'child'));
217+
$o = 3;
218+
foreach ($result as $row) {
219+
$this->assertEquals($o, $row->parent_id);
220+
--$o;
221+
}
222+
}
223+
192224
public function testPosgreSQLDisconnect()
193225
{
194226
$this->assertTrue($this->object->connect('pgsql:host=' . self::TEST_DB_HOST . ';dbname=' . self::TEST_DB_NAME . ';port=' . self::TEST_DB_PORT, self::TEST_DB_USER, self::TEST_DB_PASSWORD));

tests/pdo/pdo_sqliteTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,41 @@ public function testSelecting()
216216
$this->assertEquals(1, $this->object->query('DROP TABLE unit_test'));
217217
}
218218

219+
public function testJoins()
220+
{
221+
$this->assertTrue($this->object->connect('sqlite:' . self::TEST_SQLITE_DB, '', '', array(), true));
222+
$this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), PRIMARY KEY (ID))');
223+
$this->object->insert('unit_test', array('id' => '1', 'test_key' => 'testing 1'));
224+
$this->object->insert('unit_test', array('id' => '2', 'test_key' => 'testing 2'));
225+
$this->object->insert('unit_test', array('id' => '3', 'test_key' => 'testing 3'));
226+
$this->object->query('CREATE TABLE unit_test_child(child_id integer, child_test_key varchar(50), parent_id integer, PRIMARY KEY (child_id))');
227+
$this->object->insert('unit_test', array('child_id' => '1', 'child_test_key' => 'testing child 1', 'parent_id' => '3'));
228+
$this->object->insert('unit_test', array('child_id' => '2', 'child_test_key' => 'testing child 2', 'parent_id' => '2'));
229+
$this->object->insert('unit_test', array('child_id' => '3', 'child_test_key' => 'testing child 3', 'parent_id' => '1'));
230+
231+
$result = $this->object->selecting('unit_test_child', '*', leftJoin('unit_test_child', 'unit_test', 'parent_id', 'id'));
232+
$i = 1;
233+
$o = 3;
234+
foreach ($result as $row) {
235+
$this->assertEquals($i, $row->child_id);
236+
$this->assertEquals('testing child ' . $i, $row->child_test_key);
237+
$this->assertEquals($o, $row->id);
238+
$this->assertEquals('testing ' . $o, $row->test_key);
239+
++$i;
240+
--$o;
241+
}
242+
243+
$result = $this->object->selecting('unit_test_child', 'child.parent_id', leftJoin('unit_test_child', 'unit_test', 'parent_id', 'id', 'child'));
244+
$o = 3;
245+
foreach ($result as $row) {
246+
$this->assertEquals($o, $row->parent_id);
247+
--$o;
248+
}
249+
250+
$this->assertEquals(1, $this->object->query('DROP TABLE unit_test'));
251+
$this->assertEquals(1, $this->object->query('DROP TABLE unit_test_child'));
252+
}
253+
219254
public function testSQLiteDisconnect()
220255
{
221256
$this->assertTrue($this->object->connect());

0 commit comments

Comments
 (0)