Skip to content

Commit

Permalink
MDL-35479 fix ddl tests to use debugging asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Sep 17, 2012
1 parent 5388ff5 commit d9ba3c4
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions lib/ddl/tests/ddl_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,12 @@ public function test_table_exists() {
// first make sure it returns false if table does not exist
$table = $this->tables['test_table0'];

ob_start(); // hide debug warning
try {
$result = $DB->get_records('test_table0');
} catch (dml_exception $e) {
$result = false;
}
ob_end_clean();
$this->resetDebugging();

$this->assertFalse($result);

Expand All @@ -183,13 +182,12 @@ public function test_table_exists() {
// drop table and test again
$dbman->drop_table($table);

ob_start(); // hide debug warning
try {
$result = $DB->get_records('test_table0');
} catch (dml_exception $e) {
$result = false;
}
ob_end_clean();
$this->resetDebugging();

$this->assertFalse($result);

Expand Down Expand Up @@ -1123,13 +1121,12 @@ public function testChangeFieldNullability() {
$record = new stdClass();
$record->name = NULL;

ob_start(); // hide debug warning
try {
$result = $DB->insert_record('test_table_cust0', $record, false);
} catch (dml_exception $e) {
$result = false;
}
ob_end_clean();
$this->resetDebugging();
$this->assertFalse($result);

$field = new xmldb_field('name');
Expand All @@ -1145,13 +1142,12 @@ public function testChangeFieldNullability() {
$field->set_attributes(XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null);
$dbman->change_field_notnull($table, $field);

ob_start(); // hide debug warning
try {
$result = $DB->insert_record('test_table_cust0', $record, false);
} catch (dml_exception $e) {
$result = false;
}
ob_end_clean();
$this->resetDebugging();
$this->assertFalse($result);

$dbman->drop_table($table);
Expand Down Expand Up @@ -1214,13 +1210,12 @@ public function testAddUniqueIndex() {
$index->set_attributes(XMLDB_INDEX_UNIQUE, array('onenumber', 'name'));
$dbman->add_index($table, $index);

ob_start(); // hide debug warning
try {
$result = $DB->insert_record('test_table_cust0', $record, false);
} catch (dml_exception $e) {
$result = false;;
}
ob_end_clean();
$this->resetDebugging();
$this->assertFalse($result);

$dbman->drop_table($table);
Expand Down Expand Up @@ -1398,12 +1393,10 @@ public function testDeleteTablesFromXmldbFile() {

// feed nonexistent file
try {
ob_start(); // hide debug warning
$dbman->delete_tables_from_xmldb_file('fpsoiudfposui');
ob_end_clean();
$this->assertTrue(false);
} catch (Exception $e) {
ob_end_clean();
$this->resetDebugging();
$this->assertTrue($e instanceof moodle_exception);
}

Expand All @@ -1414,12 +1407,10 @@ public function testDeleteTablesFromXmldbFile() {
$devhack = true;
}
try {
ob_start(); // hide debug warning
$dbman->delete_tables_from_xmldb_file(__DIR__ . '/fixtures/invalid.xml');
$this->assertTrue(false);
ob_end_clean();
} catch (Exception $e) {
ob_end_clean();
$this->resetDebugging();
$this->assertTrue($e instanceof moodle_exception);
}
if ($devhack) {
Expand All @@ -1443,12 +1434,10 @@ public function testInstallFromXmldbFile() {

// feed nonexistent file
try {
ob_start(); // hide debug warning
$dbman->install_from_xmldb_file('fpsoiudfposui');
ob_end_clean();
$this->assertTrue(false);
} catch (Exception $e) {
ob_end_clean();
$this->resetDebugging();
$this->assertTrue($e instanceof moodle_exception);
}

Expand All @@ -1459,12 +1448,10 @@ public function testInstallFromXmldbFile() {
$devhack = true;
}
try {
ob_start(); // hide debug warning
$dbman->install_from_xmldb_file(__DIR__ . '/fixtures/invalid.xml');
ob_end_clean();
$this->assertTrue(false);
} catch (Exception $e) {
ob_end_clean();
$this->resetDebugging();
$this->assertTrue($e instanceof moodle_exception);
}
if ($devhack) {
Expand Down

0 comments on commit d9ba3c4

Please sign in to comment.