Skip to content

Commit

Permalink
MDL-67353 course: move form tearDown() to reset_all_data()
Browse files Browse the repository at this point in the history
We are already cleaning all sort of caches, statics, singletons
there and it's better to ensure they are always reset to avoid
myterious failures @ distance.
  • Loading branch information
stronk7 committed Jan 29, 2020
1 parent e46a987 commit 4af44db
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 49 deletions.
2 changes: 1 addition & 1 deletion course/classes/customfield/course_handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static function create(int $itemid = 0) : \core_customfield\handler {
/**
* Run reset code after unit tests to reset the singleton usage.
*/
public static function reset_after_test(): void {
public static function reset_caches(): void {
if (!PHPUNIT_TEST) {
throw new \coding_exception('This feature is only intended for use in unit tests');
}
Expand Down
8 changes: 0 additions & 8 deletions customfield/tests/api_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,6 @@
*/
class core_customfield_api_testcase extends advanced_testcase {

/**
* Tear down to reset the singleton after each test.
*/
public function tearDown() {
core_course\customfield\course_handler::reset_after_test();
parent::tearDown();
}

/**
* Get generator.
*
Expand Down
8 changes: 0 additions & 8 deletions customfield/tests/category_controller_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@
*/
class core_customfield_category_controller_testcase extends advanced_testcase {

/**
* Tear down to reset the singleton after each test.
*/
public function tearDown() {
core_course\customfield\course_handler::reset_after_test();
parent::tearDown();
}

/**
* Get generator.
*
Expand Down
8 changes: 0 additions & 8 deletions customfield/tests/data_controller_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,6 @@
*/
class core_customfield_data_controller_testcase extends advanced_testcase {

/**
* Tear down to reset the singleton after each test.
*/
public function tearDown() {
core_course\customfield\course_handler::reset_after_test();
parent::tearDown();
}

/**
* Get generator.
*
Expand Down
8 changes: 0 additions & 8 deletions customfield/tests/field_controller_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@
*/
class core_customfield_field_controller_testcase extends advanced_testcase {

/**
* Tear down to reset the singleton after each test.
*/
public function tearDown() {
core_course\customfield\course_handler::reset_after_test();
parent::tearDown();
}

/**
* Get generator.
*
Expand Down
8 changes: 0 additions & 8 deletions customfield/tests/generator_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,6 @@
*/
class core_customfield_generator_testcase extends advanced_testcase {

/**
* Tear down to reset the singleton after each test.
*/
public function tearDown() {
core_course\customfield\course_handler::reset_after_test();
parent::tearDown();
}

/**
* Get generator
* @return core_customfield_generator
Expand Down
8 changes: 0 additions & 8 deletions customfield/tests/privacy_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@
*/
class core_customfield_privacy_testcase extends provider_testcase {

/**
* Tear down to reset the singleton after each test.
*/
public function tearDown() {
core_course\customfield\course_handler::reset_after_test();
parent::tearDown();
}

/**
* Generate data.
*
Expand Down
3 changes: 3 additions & 0 deletions lib/phpunit/classes/util.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ public static function reset_all_data($detectchanges = false) {
if (class_exists('\core\update\checker')) {
\core\update\checker::reset_caches(true);
}
if (class_exists('\core_course\customfield\course_handler')) {
\core_course\customfield\course_handler::reset_caches();
}

// Clear static cache within restore.
if (class_exists('restore_section_structure_step')) {
Expand Down

0 comments on commit 4af44db

Please sign in to comment.