Skip to content

Commit f599492

Browse files
committed
improved BadQueryTest, simplified return value in BaseUtils::optimizeTable
1 parent 094d003 commit f599492

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

system/Database/BaseUtils.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,7 @@ public function optimizeTable(string $tableName)
136136

137137
$query = $this->db->query(sprintf($this->optimizeTable, $this->db->escapeIdentifiers($tableName)));
138138

139-
if ($query !== false)
140-
{
141-
return true;
142-
}
143-
144-
return false;
139+
return ($query !== false) ? true : false;
145140
}
146141

147142
//--------------------------------------------------------------------

tests/system/Database/Live/BadQueryTest.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,16 @@ class BadQueryTest extends CIDatabaseTestCase
1313

1414
public function testBadQuery()
1515
{
16-
// this throws an exception in this testing environment, but in production it'll return FALSE
17-
// perhaps check $this->db->DBDebug for different test?
18-
$query = $this->db->query('SELECT * FROM table_does_not_exist');
19-
$this->assertEquals(false, $query);
16+
if ($this->db->DBDebug) {
17+
// expect an exception, class and message varies by DBMS
18+
$this->expectException(\Exception::class);
19+
$query = $this->db->query('SELECT * FROM table_does_not_exist');
20+
} else {
21+
// this throws an exception in this testing environment, but in production it'll return FALSE
22+
// perhaps check $this->db->DBDebug for different test?
23+
$query = $this->db->query('SELECT * FROM table_does_not_exist');
24+
$this->assertEquals(false, $query);
25+
}
2026
}
2127

2228
}

0 commit comments

Comments
 (0)