From 71fc50031d5f4461d86602e889c8cd22d9ebc96b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20S=CC=8Ckoda?= Date: Wed, 10 Apr 2013 09:43:47 +0200 Subject: [PATCH] MDL-38989 detect changed timeout in tests The trouble is that PHPUnit should ideally test mostly low level libraries that should not change the timeouts. --- lib/phpunit/classes/advanced_testcase.php | 2 +- lib/phpunit/classes/database_driver_testcase.php | 2 +- lib/phpunit/classes/util.php | 14 +++++++++----- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/phpunit/classes/advanced_testcase.php b/lib/phpunit/classes/advanced_testcase.php index 9b9bb996791..c04d3399cde 100644 --- a/lib/phpunit/classes/advanced_testcase.php +++ b/lib/phpunit/classes/advanced_testcase.php @@ -97,7 +97,7 @@ abstract class advanced_testcase extends PHPUnit_Framework_TestCase { phpunit_util::reset_all_database_sequences(); phpunit_util::$lastdbwrites = $DB->perf_get_writes(); // no db reset necessary } - phpunit_util::reset_all_data(); + phpunit_util::reset_all_data(null); } else if ($this->resetAfterTest === false) { if ($this->testdbtransaction) { diff --git a/lib/phpunit/classes/database_driver_testcase.php b/lib/phpunit/classes/database_driver_testcase.php index f3544297b5a..f186abcf05e 100644 --- a/lib/phpunit/classes/database_driver_testcase.php +++ b/lib/phpunit/classes/database_driver_testcase.php @@ -130,7 +130,7 @@ abstract class database_driver_testcase extends PHPUnit_Framework_TestCase { self::$extradb->dispose(); self::$extradb = null; } - phpunit_util::reset_all_data(); + phpunit_util::reset_all_data(null); parent::tearDownAfterClass(); } diff --git a/lib/phpunit/classes/util.php b/lib/phpunit/classes/util.php index 4fcfda4e22e..97c7681b155 100644 --- a/lib/phpunit/classes/util.php +++ b/lib/phpunit/classes/util.php @@ -83,10 +83,13 @@ class phpunit_util extends testing_util { * Note: this is relatively slow (cca 2 seconds for pg and 7 for mysql) - please use with care! * * @static - * @param bool $logchanges log changes in global state and database in error log + * @param bool $detectchanges + * true - changes in global state and database are reported as errors + * false - no errors reported + * null - only critical problems are reported as errors * @return void */ - public static function reset_all_data($logchanges = false) { + public static function reset_all_data($detectchanges = false) { global $DB, $CFG, $USER, $SITE, $COURSE, $PAGE, $OUTPUT, $SESSION; // Stop any message redirection. @@ -110,7 +113,7 @@ class phpunit_util extends testing_util { $resetdb = self::reset_database(); $warnings = array(); - if ($logchanges) { + if ($detectchanges === true) { if ($resetdb) { $warnings[] = 'Warning: unexpected database modification, resetting DB state'; } @@ -147,8 +150,9 @@ class phpunit_util extends testing_util { // libraries to mess with timeouts unintentionally. // Our PHPUnit integration is not supposed to change it either. - // TODO: MDL-38912 uncomment and fix all + somehow resolve timeouts in failed tests. - //$warnings[] = 'Warning: max_execution_time was changed.'; + if ($detectchanges !== false) { + $warnings[] = 'Warning: max_execution_time was changed to '.ini_get('max_execution_time'); + } set_time_limit(0); }