-
Bug
-
Resolution: Fixed
-
Minor
-
4.2.1
-
MOODLE_402_STABLE
-
MOODLE_403_STABLE
-
Hi team, this issue was inspired by, and is somewhat related to MDL-76506.
If a process executes two files that have say,
file1:
include "$CFG->dirroot/lib/setup.php"; |
file2:
require("$CFG->dirroot/lib/setup.php"); |
This will cause `MDL_PERF`, `MDL_PERFDB`, and `MDL_PERFTOFOOT` to be defined as `true`, even if they are not defined in the configuration.
An example of this could be the following:
Steps to replicate
- Make sure there is a line to the same effect of (or copy this one) `require("$CFG->dirroot/lib/setup.php");` in your 'config.php' file (or equivalent configuration file that you use). Put a breakpoint on this line.
- On https://github.com/moodle/moodle/blob/master/lib/phpunit/bootstrap.php#L217 you can see that it contains `require("$CFG->dirroot/lib/setup.php");` which is the second require of 'lib/setup.php'. Put a breakpoint on this line as well.
- Setup the PhpUnit environment, and listen for debugging connections with Xdebug or similar.
- Run any PhpUnit test, e.g. `php vendor/bin/phpunit admin/tool/mobile/tests/api_test.php --filter test_get_autologin_key`.
- When you trip the breakpoint from step 1, step into that line, and execute the 'lib/setup.php' file until the line that says `if (!defined('MDL_PERF_TEST')) {`. Step over. In this first pass, `MDL_PERF_TEST` is defined as false.
- Continue execution, when the second breakpoint is tripped from step 2, step into that line, and like in step 5, continue execution up to the line that says `if (!defined('MDL_PERF_TEST')) {`. Step over a few times. In this second pass `MDL_PERF`, `MDL_PERFDB`, and `MDL_PERFTOFOOT` are defined as `true`.
Observed behavior
The constants `MDL_PERF`, `MDL_PERFDB`, and `MDL_PERFTOFOOT` are defined as `true` even when they are not defined in the configuration of the site.
Expected behavior
The constants `MDL_PERF`, `MDL_PERFDB`, and `MDL_PERFTOFOOT` are not defined, unless defined in the configuration.
Possible solution
This seems like one of those cases where the `if` can be extended from:
if (!defined('MDL_PERF_TEST')) { |
to:
if (!defined('MDL_PERF_TEST') || !MDL_PERF_TEST) { |
such that when `MDL_PERF_TEST` is already defined but is `false`, the same flow of execution is followed... I tested this solution and it works, but it produces a PHP Notice (because `MDL_PERF_TEST` was already defined in the first pass), so this may not be the appropriate solution. I guess that another solution would be to enclose the `ifs` of `MDL_PERF`, `MDL_PERFDB`, and `MDL_PERFTOFOOT`, into an `if (MDL_PERF_TEST) {`. I tested that too and it worked, without producing a PHP Notice.
Thank you for your attention to the present issue.