Merge branch 'MDL-52284-master' of git://github.com/marinaglancy/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2015-12-10 16:16:20 +01:00
commit 0a57ba06cb
9 changed files with 62 additions and 8 deletions

View file

@ -126,6 +126,9 @@ class backp_settings_testcase extends basic_testcase {
} catch (exception $e) { } catch (exception $e) {
$this->assertTrue($e instanceof base_setting_exception); $this->assertTrue($e instanceof base_setting_exception);
$this->assertEquals($e->errorcode, 'incorrect_object_passed'); $this->assertEquals($e->errorcode, 'incorrect_object_passed');
} catch (TypeError $e) {
// On PHP7+ we get a TypeError raised, lets check we've the right error.
$this->assertRegexp('/must be an instance of backup_setting_ui/', $e->getMessage());
} }
restore_error_handler(); restore_error_handler();
@ -140,6 +143,9 @@ class backp_settings_testcase extends basic_testcase {
} catch (exception $e) { } catch (exception $e) {
$this->assertTrue($e instanceof base_setting_exception); $this->assertTrue($e instanceof base_setting_exception);
$this->assertEquals($e->errorcode, 'incorrect_object_passed'); $this->assertEquals($e->errorcode, 'incorrect_object_passed');
} catch (TypeError $e) {
// On PHP7+ we get a TypeError raised, lets check we've the right error.
$this->assertRegexp('/must be an instance of backup_setting_ui/', $e->getMessage());
} }
restore_error_handler(); restore_error_handler();
@ -302,6 +308,9 @@ class backp_settings_testcase extends basic_testcase {
} catch (exception $e) { } catch (exception $e) {
$this->assertTrue($e instanceof backup_setting_exception); $this->assertTrue($e instanceof backup_setting_exception);
$this->assertEquals($e->errorcode, 'incorrect_object_passed'); $this->assertEquals($e->errorcode, 'incorrect_object_passed');
} catch (TypeError $e) {
// On PHP7+ we get a TypeError raised, lets check we've the right error.
$this->assertRegexp('/must be an instance of base_setting/', $e->getMessage());
} }
restore_error_handler(); restore_error_handler();

View file

@ -81,6 +81,9 @@ class core_shutdown_manager {
} }
} catch (Exception $e) { } catch (Exception $e) {
error_log('Exception ignored in shutdown function '.var_export($callback, true).':'.$e->getMessage()); error_log('Exception ignored in shutdown function '.var_export($callback, true).':'.$e->getMessage());
} catch (Throwable $e) {
// Engine errors in PHP7 throw exceptions of type Throwable (this "catch" will be ignored in PHP5).
error_log('Exception ignored in shutdown function '.var_export($callback, true).':'.$e->getMessage());
} }
} }

View file

@ -2431,10 +2431,14 @@ abstract class moodle_database {
* automatically if exceptions not caught. * automatically if exceptions not caught.
* *
* @param moodle_transaction $transaction An instance of a moodle_transaction. * @param moodle_transaction $transaction An instance of a moodle_transaction.
* @param Exception $e The related exception to this transaction rollback. * @param Exception|Throwable $e The related exception/throwable to this transaction rollback.
* @return void This does not return, instead the exception passed in will be rethrown. * @return void This does not return, instead the exception passed in will be rethrown.
*/ */
public function rollback_delegated_transaction(moodle_transaction $transaction, Exception $e) { public function rollback_delegated_transaction(moodle_transaction $transaction, $e) {
if (!($e instanceof Exception) && !($e instanceof Throwable)) {
// PHP7 - we catch Throwables in phpunit but can't use that as the type hint in PHP5.
$e = new \coding_exception("Must be given an Exception or Throwable object!");
}
if ($transaction->is_disposed()) { if ($transaction->is_disposed()) {
throw new dml_transaction_exception('Transactions already disposed', $transaction); throw new dml_transaction_exception('Transactions already disposed', $transaction);
} }

View file

@ -95,10 +95,10 @@ class moodle_transaction {
/** /**
* Rollback all current delegated transactions. * Rollback all current delegated transactions.
* *
* @param Exception $e mandatory exception * @param Exception|Throwable $e mandatory exception/throwable
* @return void * @return void
*/ */
public function rollback(Exception $e) { public function rollback($e) {
if ($this->is_disposed()) { if ($this->is_disposed()) {
throw new dml_transaction_exception('Transactions already disposed', $this); throw new dml_transaction_exception('Transactions already disposed', $this);
} }

View file

@ -88,7 +88,14 @@ abstract class advanced_testcase extends base_testcase {
trigger_error('Unexpected debugging() call detected.', E_USER_NOTICE); trigger_error('Unexpected debugging() call detected.', E_USER_NOTICE);
} }
} catch (Exception $e) { } catch (Exception $ex) {
$e = $ex;
} catch (Throwable $ex) {
// Engine errors in PHP7 throw exceptions of type Throwable (this "catch" will be ignored in PHP5).
$e = $ex;
}
if (isset($e)) {
// cleanup after failed expectation // cleanup after failed expectation
self::resetAllData(); self::resetAllData();
throw $e; throw $e;

View file

@ -62,7 +62,15 @@ abstract class basic_testcase extends base_testcase {
try { try {
parent::runBare(); parent::runBare();
} catch (Exception $e) {
} catch (Exception $ex) {
$e = $ex;
} catch (Throwable $ex) {
// Engine errors in PHP7 throw exceptions of type Throwable (this "catch" will be ignored in PHP5).
$e = $ex;
}
if (isset($e)) {
// cleanup after failed expectation // cleanup after failed expectation
phpunit_util::reset_all_data(); phpunit_util::reset_all_data();
throw $e; throw $e;

View file

@ -142,7 +142,14 @@ abstract class database_driver_testcase extends base_testcase {
try { try {
parent::runBare(); parent::runBare();
} catch (Exception $e) { } catch (Exception $ex) {
$e = $ex;
} catch (Throwable $ex) {
// Engine errors in PHP7 throw exceptions of type Throwable (this "catch" will be ignored in PHP5).
$e = $ex;
}
if (isset($e)) {
if ($this->tdb->is_transaction_started()) { if ($this->tdb->is_transaction_started()) {
$this->tdb->force_transaction_rollback(); $this->tdb->force_transaction_rollback();
} }

View file

@ -378,7 +378,14 @@ function default_exception_handler($ex) {
$DB->set_debug(0); $DB->set_debug(0);
} }
echo $OUTPUT->fatal_error($info->message, $info->moreinfourl, $info->link, $info->backtrace, $info->debuginfo); echo $OUTPUT->fatal_error($info->message, $info->moreinfourl, $info->link, $info->backtrace, $info->debuginfo);
} catch (Exception $out_ex) { } catch (Exception $e) {
$out_ex = $e;
} catch (Throwable $e) {
// Engine errors in PHP7 throw exceptions of type Throwable (this "catch" will be ignored in PHP5).
$out_ex = $e;
}
if (isset($out_ex)) {
// default exception handler MUST not throw any exceptions!! // default exception handler MUST not throw any exceptions!!
// the problem here is we do not know if page already started or not, we only know that somebody messed up in outputlib or theme // the problem here is we do not know if page already started or not, we only know that somebody messed up in outputlib or theme
// so we just print at least something instead of "Exception thrown without a stack frame in Unknown on line 0":-( // so we just print at least something instead of "Exception thrown without a stack frame in Unknown on line 0":-(

View file

@ -1547,6 +1547,9 @@ function install_core($version, $verbose) {
cache_helper::purge_all(); cache_helper::purge_all();
} catch (exception $ex) { } catch (exception $ex) {
upgrade_handle_exception($ex); upgrade_handle_exception($ex);
} catch (Throwable $ex) {
// Engine errors in PHP7 throw exceptions of type Throwable (this "catch" will be ignored in PHP5).
upgrade_handle_exception($ex);
} }
} }
@ -1617,6 +1620,9 @@ function upgrade_core($version, $verbose) {
print_upgrade_part_end('moodle', false, $verbose); print_upgrade_part_end('moodle', false, $verbose);
} catch (Exception $ex) { } catch (Exception $ex) {
upgrade_handle_exception($ex); upgrade_handle_exception($ex);
} catch (Throwable $ex) {
// Engine errors in PHP7 throw exceptions of type Throwable (this "catch" will be ignored in PHP5).
upgrade_handle_exception($ex);
} }
} }
@ -1651,6 +1657,9 @@ function upgrade_noncore($verbose) {
} catch (Exception $ex) { } catch (Exception $ex) {
upgrade_handle_exception($ex); upgrade_handle_exception($ex);
} catch (Throwable $ex) {
// Engine errors in PHP7 throw exceptions of type Throwable (this "catch" will be ignored in PHP5).
upgrade_handle_exception($ex);
} }
} }