Skip to content

Commit b0dd905

Browse files
Change testAssertTypeReturning to testReturning; remove dynamic $assertType and instead use if statement
1 parent d2c6162 commit b0dd905

File tree

1 file changed

+79
-53
lines changed

1 file changed

+79
-53
lines changed

tests/system/Database/Live/WriteTypeQueryTest.php

Lines changed: 79 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,17 @@ final class WriteTypeQueryTest extends CIUnitTestCase
2929
protected $seed = CITestSeeder::class;
3030

3131
/**
32-
* Whether CodeIgniter ignores RETURNING for isWriteType.
32+
* Whether CodeIgniter considers RETURNING in isWriteType.
3333
*
3434
* Currently, only Postgre is supported by CodeIgniter.
3535
* This method should be updated if support for RETURNING
36-
* is expanded to other databases.
36+
* is expanded for other databases.
3737
*
3838
* @param string $dbDriver
3939
*/
40-
private function testAssertTypeReturning($dbDriver): string
40+
private function testReturning($dbDriver): bool
4141
{
42-
if ($dbDriver === 'Postgre') {
43-
return 'assertFalse';
44-
}
45-
46-
return 'assertTrue';
42+
return $dbDriver === 'Postgre';
4743
}
4844

4945
public function testSet(): void
@@ -114,9 +110,11 @@ public function testInsertOneReturning(): void
114110
{
115111
$sql = "INSERT INTO my_table (col1, col2) VALUES ('Joe', 'Cool') RETURNING id;";
116112

117-
$assertType = $this->testAssertTypeReturning($this->db->DBDriver);
118-
119-
$this->{$assertType}($this->db->isWriteType($sql));
113+
if ($this->testReturning($this->db->DBDriver)) {
114+
$this->assertFalse($this->db->isWriteType($sql));
115+
} else {
116+
$this->assertTrue($this->db->isWriteType($sql));
117+
}
120118
}
121119

122120
public function testInsertMultiReturning(): void
@@ -127,27 +125,33 @@ public function testInsertMultiReturning(): void
127125
RETURNING id;
128126
SQL;
129127

130-
$assertType = $this->testAssertTypeReturning($this->db->DBDriver);
131-
132-
$this->{$assertType}($this->db->isWriteType($sql));
128+
if ($this->testReturning($this->db->DBDriver)) {
129+
$this->assertFalse($this->db->isWriteType($sql));
130+
} else {
131+
$this->assertTrue($this->db->isWriteType($sql));
132+
}
133133
}
134134

135135
public function testInsertWithOneReturning(): void
136136
{
137137
$sql = "WITH seqvals AS (SELECT '3' AS seqval) INSERT INTO my_table (col1, col2) SELECT 'Joe', seqval FROM seqvals RETURNING id;";
138138

139-
$assertType = $this->testAssertTypeReturning($this->db->DBDriver);
140-
141-
$this->{$assertType}($this->db->isWriteType($sql));
139+
if ($this->testReturning($this->db->DBDriver)) {
140+
$this->assertFalse($this->db->isWriteType($sql));
141+
} else {
142+
$this->assertTrue($this->db->isWriteType($sql));
143+
}
142144
}
143145

144146
public function testInsertWithOneReturningNoSpace(): void
145147
{
146148
$sql = "WITH seqvals AS (SELECT '3' AS seqval)INSERT INTO my_table (col1, col2) SELECT 'Joe', seqval FROM seqvals RETURNING id;";
147149

148-
$assertType = $this->testAssertTypeReturning($this->db->DBDriver);
149-
150-
$this->{$assertType}($this->db->isWriteType($sql));
150+
if ($this->testReturning($this->db->DBDriver)) {
151+
$this->assertFalse($this->db->isWriteType($sql));
152+
} else {
153+
$this->assertTrue($this->db->isWriteType($sql));
154+
}
151155
}
152156

153157
public function testInsertWithMultiReturning(): void
@@ -160,9 +164,11 @@ public function testInsertWithMultiReturning(): void
160164
RETURNING id;
161165
SQL;
162166

163-
$assertType = $this->testAssertTypeReturning($this->db->DBDriver);
164-
165-
$this->{$assertType}($this->db->isWriteType($sql));
167+
if ($this->testReturning($this->db->DBDriver)) {
168+
$this->assertFalse($this->db->isWriteType($sql));
169+
} else {
170+
$this->assertTrue($this->db->isWriteType($sql));
171+
}
166172
}
167173

168174
public function testUpdateBuilder(): void
@@ -223,9 +229,11 @@ public function testUpdateOneReturning(): void
223229
{
224230
$sql = "UPDATE my_table SET col1 = 'foo' WHERE id = 2 RETURNING *;";
225231

226-
$assertType = $this->testAssertTypeReturning($this->db->DBDriver);
227-
228-
$this->{$assertType}($this->db->isWriteType($sql));
232+
if ($this->testReturning($this->db->DBDriver)) {
233+
$this->assertFalse($this->db->isWriteType($sql));
234+
} else {
235+
$this->assertTrue($this->db->isWriteType($sql));
236+
}
229237
}
230238

231239
public function testUpdateMultiReturning(): void
@@ -237,27 +245,33 @@ public function testUpdateMultiReturning(): void
237245
RETURNING *;
238246
SQL;
239247

240-
$assertType = $this->testAssertTypeReturning($this->db->DBDriver);
241-
242-
$this->{$assertType}($this->db->isWriteType($sql));
248+
if ($this->testReturning($this->db->DBDriver)) {
249+
$this->assertFalse($this->db->isWriteType($sql));
250+
} else {
251+
$this->assertTrue($this->db->isWriteType($sql));
252+
}
243253
}
244254

245255
public function testUpdateWithOneReturning(): void
246256
{
247257
$sql = "WITH seqvals AS (SELECT '3' AS seqval) UPDATE my_table SET col1 = seqval FROM seqvals WHERE id = 2 RETURNING *;";
248258

249-
$assertType = $this->testAssertTypeReturning($this->db->DBDriver);
250-
251-
$this->{$assertType}($this->db->isWriteType($sql));
259+
if ($this->testReturning($this->db->DBDriver)) {
260+
$this->assertFalse($this->db->isWriteType($sql));
261+
} else {
262+
$this->assertTrue($this->db->isWriteType($sql));
263+
}
252264
}
253265

254266
public function testUpdateWithOneReturningNoSpace(): void
255267
{
256268
$sql = "WITH seqvals AS (SELECT '3' AS seqval)UPDATE my_table SET col1 = seqval FROM seqvals WHERE id = 2 RETURNING *;";
257269

258-
$assertType = $this->testAssertTypeReturning($this->db->DBDriver);
259-
260-
$this->{$assertType}($this->db->isWriteType($sql));
270+
if ($this->testReturning($this->db->DBDriver)) {
271+
$this->assertFalse($this->db->isWriteType($sql));
272+
} else {
273+
$this->assertTrue($this->db->isWriteType($sql));
274+
}
261275
}
262276

263277
public function testUpdateWithMultiReturning(): void
@@ -271,9 +285,11 @@ public function testUpdateWithMultiReturning(): void
271285
RETURNING *;
272286
SQL;
273287

274-
$assertType = $this->testAssertTypeReturning($this->db->DBDriver);
275-
276-
$this->{$assertType}($this->db->isWriteType($sql));
288+
if ($this->testReturning($this->db->DBDriver)) {
289+
$this->assertFalse($this->db->isWriteType($sql));
290+
} else {
291+
$this->assertTrue($this->db->isWriteType($sql));
292+
}
277293
}
278294

279295
public function testDeleteBuilder(): void
@@ -332,9 +348,11 @@ public function testDeleteOneReturning(): void
332348
{
333349
$sql = 'DELETE FROM my_table WHERE id = 2 RETURNING *;';
334350

335-
$assertType = $this->testAssertTypeReturning($this->db->DBDriver);
336-
337-
$this->{$assertType}($this->db->isWriteType($sql));
351+
if ($this->testReturning($this->db->DBDriver)) {
352+
$this->assertFalse($this->db->isWriteType($sql));
353+
} else {
354+
$this->assertTrue($this->db->isWriteType($sql));
355+
}
338356
}
339357

340358
public function testDeleteMultiReturning(): void
@@ -345,27 +363,33 @@ public function testDeleteMultiReturning(): void
345363
RETURNING *;
346364
SQL;
347365

348-
$assertType = $this->testAssertTypeReturning($this->db->DBDriver);
349-
350-
$this->{$assertType}($this->db->isWriteType($sql));
366+
if ($this->testReturning($this->db->DBDriver)) {
367+
$this->assertFalse($this->db->isWriteType($sql));
368+
} else {
369+
$this->assertTrue($this->db->isWriteType($sql));
370+
}
351371
}
352372

353373
public function testDeleteWithOneReturning(): void
354374
{
355375
$sql = "WITH seqvals AS (SELECT '3' AS seqval) DELETE FROM my_table JOIN seqvals ON col1 = seqval RETURNING *;";
356376

357-
$assertType = $this->testAssertTypeReturning($this->db->DBDriver);
358-
359-
$this->{$assertType}($this->db->isWriteType($sql));
377+
if ($this->testReturning($this->db->DBDriver)) {
378+
$this->assertFalse($this->db->isWriteType($sql));
379+
} else {
380+
$this->assertTrue($this->db->isWriteType($sql));
381+
}
360382
}
361383

362384
public function testDeleteWithOneReturningNoSpace(): void
363385
{
364386
$sql = "WITH seqvals AS (SELECT '3' AS seqval)DELETE FROM my_table JOIN seqvals ON col1 = seqval RETURNING *;";
365387

366-
$assertType = $this->testAssertTypeReturning($this->db->DBDriver);
367-
368-
$this->{$assertType}($this->db->isWriteType($sql));
388+
if ($this->testReturning($this->db->DBDriver)) {
389+
$this->assertFalse($this->db->isWriteType($sql));
390+
} else {
391+
$this->assertTrue($this->db->isWriteType($sql));
392+
}
369393
}
370394

371395
public function testDeleteWithMultiReturning(): void
@@ -379,9 +403,11 @@ public function testDeleteWithMultiReturning(): void
379403
RETURNING *;
380404
SQL;
381405

382-
$assertType = $this->testAssertTypeReturning($this->db->DBDriver);
383-
384-
$this->{$assertType}($this->db->isWriteType($sql));
406+
if ($this->testReturning($this->db->DBDriver)) {
407+
$this->assertFalse($this->db->isWriteType($sql));
408+
} else {
409+
$this->assertTrue($this->db->isWriteType($sql));
410+
}
385411
}
386412

387413
public function testReplace(): void

0 commit comments

Comments
 (0)