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

Unit test failures in Moodle 3.11 - "Undefined property: stdClass::$country"

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 3.11
    • Fix Version/s: None
    • Component/s: Unit tests
    • Labels:
      None
    • Affected Branches:
      MOODLE_311_STABLE

      Description

      When I try to run the Moodle unit tests, it seems like every unit test that creates a test user fails for me with this error (originating test case file and line will change depending on the unit test, of course):

      Undefined property: stdClass::$country
       
      /mnt/code/www/moodle_prod/lib/classes/user.php:677
      /mnt/code/www/moodle_prod/lib/classes/user.php:845
      /mnt/code/www/moodle_prod/lib/classes/user.php:814
      /mnt/code/www/moodle_prod/user/lib.php:59
      /mnt/code/www/moodle_prod/lib/testing/generator/data_generator.php:227
      /mnt/code/www/moodle_prod/lib/phpunit/tests/advanced_test.php:192
      /mnt/code/www/moodle_prod/lib/phpunit/classes/advanced_testcase.php:80
      

      Setting $CFG->country in the config.php file seems to have no effect on the error.

      I'm running the unit tests on CentOS 7.9 with PHP 7.4.18 and MariaDB 10.3.27.

      The apparent cause is that $CFG->country is not defined in the unit tests, and the lib/classes/user.php method fill_properties_cache()  uses the value without checking that it is actually set on line 677.

      I checked the unit testing config table (phpu_config) and it does not contain a value for country (mdl_config does). 

      Note: This error does not appear to be new for Moodle 3.11, I have seen a nearly identical error on Moodle 3.7 (PHP 7.1.29) (same error, different line number).  Strangely, the error does not occur on my Moodle 3.9 test server (PHP 7.2.31).

      The primary difference appears to be that the Moodle 3.9 site actually puts a value for country into the unit test config table. I do not yet know why the Moodle 3.7 and Moodle 3.11 sites do not create a country value in the unit test config table.

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            tbannister Tyler Bannister
            Participants:
            Component watchers:
            Andrew Lyons, Dongsheng Cai, Huong Nguyen, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: