Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-70245

Static variable $cache in grade_get_setting causes unit test failures

    XMLWordPrintable

Details

    • MOODLE_310_STABLE, MOODLE_37_STABLE, MOODLE_38_STABLE, MOODLE_39_STABLE
    • MOODLE_310_STABLE, MOODLE_39_STABLE
    • MDL-70245-MOODLE_39_STABLE
    • MDL-70245-master
    • Hide

      Run Unit Tests

      1. Replicate the issue by a failing unit test that should not fail
        Apply 0001-MDL-70245-test-patch.patch  (Please find the attached for this)
        git am 0001-MDL-70245-test-patch.patch
      2. Run vendor/bin/phpunit lib/tests/upgradelib_test.php
        Test failed
        core_upgradelib_testcase::test_upgrade_update_category_grademax_regrade_final_grades
        Failed asserting that '10.00000' matches expected 20.
      3. Apply the solution in this tracker. There could be merge conflict since we included the same unit test in the solution
      4. Run same test vendor/bin/phpunit lib/tests/upgradelib_test.php

      Expected:

              The failing unit test passed

      Show
      Run Unit Tests Replicate the issue by a failing unit test that should not fail Apply 0001- MDL-70245 -test-patch.patch  (Please find the attached for this) git am 0001- MDL-70245 -test-patch.patch Run vendor/bin/phpunit lib/tests/upgradelib_test.php Test failed core_upgradelib_testcase::test_upgrade_update_category_grademax_regrade_final_grades Failed asserting that '10.00000' matches expected 20. Apply the solution in this tracker. There could be merge conflict since we included the same unit test in the solution Run same test vendor/bin/phpunit lib/tests/upgradelib_test.php Expected:         The failing unit test passed

    Description

      When the unit test tries to validate "finalgrade" with different set of grade max, then it will fail after "test_upgrade_calculated_grade_items_freeze" function in core_testsuite because the static $cache variable does not reset and the "minmaxtouse" collides with previous unit tests.

       

      Steps to reproduce:

      1. Write unit test (attached in MDL-70245-patch.txt) that implement to validate "finalgrade" with different set of grademax (for course category and grade item) after the function "test_upgrade_calculated_grade_items_freeze" .
      2. Run vendor/bin/phpunit --testsuite=core_testsuite

       

      Expected:

      Unit tests pass

       

      Actual:

      Unit tests fail with unexpected "finalgrade" getting returned (because it is using the previous "minmaxtouse" which is set in the function "test_upgrade_calculated_grade_items_freeze")

       

       

      Attachments

        Activity

          People

            tomotsuyuki Tomo Tsuyuki
            anupamadharmajan Anupama Dharmajan
            John Yao John Yao
            Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
            Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
            Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Sujith Haridasan, Andrew Lyons, Huong Nguyen, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              18/Jan/21

              Time Tracking

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 45 minutes
                45m