From c42d18183a633625745d089523971de8e6aaadaa Mon Sep 17 00:00:00 2001 From: Adrian Greeve Date: Mon, 20 Oct 2014 14:21:53 +0800 Subject: [PATCH] MDL-47675 phpunit: Update unit tests to pass on MSSQL Unit tests were failing on MSSQL. gc_collect_cycles() was removed from the phpunit utils.php file to save time in running the tests, but MSSQL doesn't clean up open files as well as other databases. This patch includes the garbage collection for the unit tests that require it. --- admin/tool/uploadcourse/tests/course_test.php | 7 +++++++ admin/tool/uploadcourse/tests/processor_test.php | 7 +++++++ backup/moodle2/tests/moodle2_test.php | 7 +++++++ course/tests/courselib_test.php | 7 +++++++ course/tests/externallib_test.php | 7 +++++++ lib/tests/questionlib_test.php | 7 +++++++ mod/assign/feedback/editpdf/tests/editpdf_test.php | 7 +++++++ 7 files changed, 49 insertions(+) diff --git a/admin/tool/uploadcourse/tests/course_test.php b/admin/tool/uploadcourse/tests/course_test.php index fd33545a768..a173e721811 100644 --- a/admin/tool/uploadcourse/tests/course_test.php +++ b/admin/tool/uploadcourse/tests/course_test.php @@ -35,6 +35,13 @@ global $CFG; */ class tool_uploadcourse_course_testcase extends advanced_testcase { + /** + * Tidy up open files that may be left open. + */ + protected function tearDown() { + gc_collect_cycles(); + } + public function test_proceed_without_prepare() { $this->resetAfterTest(true); $mode = tool_uploadcourse_processor::MODE_CREATE_NEW; diff --git a/admin/tool/uploadcourse/tests/processor_test.php b/admin/tool/uploadcourse/tests/processor_test.php index 1dd20dc1927..2d2ec04456b 100644 --- a/admin/tool/uploadcourse/tests/processor_test.php +++ b/admin/tool/uploadcourse/tests/processor_test.php @@ -36,6 +36,13 @@ require_once($CFG->libdir . '/csvlib.class.php'); */ class tool_uploadcourse_processor_testcase extends advanced_testcase { + /** + * Tidy up open files that may be left open. + */ + protected function tearDown() { + gc_collect_cycles(); + } + public function test_basic() { global $DB; $this->resetAfterTest(true); diff --git a/backup/moodle2/tests/moodle2_test.php b/backup/moodle2/tests/moodle2_test.php index bb937aa65d5..960c9eca09d 100644 --- a/backup/moodle2/tests/moodle2_test.php +++ b/backup/moodle2/tests/moodle2_test.php @@ -38,6 +38,13 @@ require_once($CFG->libdir . '/completionlib.php'); */ class core_backup_moodle2_testcase extends advanced_testcase { + /** + * Tidy up open files that may be left open. + */ + protected function tearDown() { + gc_collect_cycles(); + } + /** * Tests the availability field on modules and sections is correctly * backed up and restored. diff --git a/course/tests/courselib_test.php b/course/tests/courselib_test.php index 62ac25a5d95..77ef9e0f234 100644 --- a/course/tests/courselib_test.php +++ b/course/tests/courselib_test.php @@ -33,6 +33,13 @@ require_once($CFG->dirroot . '/tag/lib.php'); class core_course_courselib_testcase extends advanced_testcase { + /** + * Tidy up open files that may be left open. + */ + protected function tearDown() { + gc_collect_cycles(); + } + /** * Set forum specific test values for calling create_module(). * diff --git a/course/tests/externallib_test.php b/course/tests/externallib_test.php index 13826b87809..756c626f533 100644 --- a/course/tests/externallib_test.php +++ b/course/tests/externallib_test.php @@ -47,6 +47,13 @@ class core_course_externallib_testcase extends externallib_advanced_testcase { require_once($CFG->dirroot . '/course/externallib.php'); } + /** + * Tidy up open files that may be left open. + */ + protected function tearDown() { + gc_collect_cycles(); + } + /** * Test create_categories */ diff --git a/lib/tests/questionlib_test.php b/lib/tests/questionlib_test.php index 1b0c2bcfebf..10b4007a031 100644 --- a/lib/tests/questionlib_test.php +++ b/lib/tests/questionlib_test.php @@ -51,6 +51,13 @@ class core_questionlib_testcase extends advanced_testcase { $this->resetAfterTest(); } + /** + * Tidy up open files that may be left open. + */ + protected function tearDown() { + gc_collect_cycles(); + } + public function test_question_reorder_qtypes() { $this->assertEquals( array(0 => 't2', 1 => 't1', 2 => 't3'), diff --git a/mod/assign/feedback/editpdf/tests/editpdf_test.php b/mod/assign/feedback/editpdf/tests/editpdf_test.php index 6afe93ffa8b..207a64bd299 100644 --- a/mod/assign/feedback/editpdf/tests/editpdf_test.php +++ b/mod/assign/feedback/editpdf/tests/editpdf_test.php @@ -52,6 +52,13 @@ class assignfeedback_editpdf_testcase extends mod_assign_base_testcase { parent::setUp(); } + /** + * Tidy up open files that may be left open. + */ + protected function tearDown() { + gc_collect_cycles(); + } + protected function create_assign_and_submit_pdf() { global $CFG; $assign = $this->create_instance(array('assignsubmission_onlinetext_enabled' => 1,