Closed mudrd8mz closed 2 years ago
Hi @mudrd8mz.
The fix invalidates the primary purpose of declaring the variable in config.php
, which is to help VSCode resolve $DB
. I have not seen the error you are reporting, would you be provide steps for me to replicate it?
An alternative patch might be:
/** @var moodle_database */
$DB = isset($DB) ? $DB : null;
Thanks!
$ mdk create -v 400 -n test400 -i
$ gt test400
$ mdk run dev
$ mdk phpunit
$ mdk phpunit
Initialising Moodle PHPUnit test environment...
You are already using the latest available Composer version 2.3.6 (stable channel).
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Nothing to install, update or remove
Generating autoload files
52 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
PHP Notice: Undefined variable: DB in /home/mudrd8mz/www/mdk/test400/moodle/config.php on line 41
IIRC there is something related to the fact how PHPUnit includes Moodle files. We had to use global $CFG
for that reasons in some places, too.
Yes, likely caused by an inclusion within a function/method. I'm not seeing the notice myself, is that PHP 8?
PHP 7.4.28 with
$ php -i | grep '\(error_reporting\|display_errors\)'
display_errors => STDOUT => STDOUT
error_reporting => 32767 => 32767
Right. Does this solve it?
/** @var moodle_database */
$DB = isset($DB) ? $DB : null;
If not, we can remove these altogether, VS Code still doesn't seem to reliably resolve $DB
.
Does this solve it?
It does. I've amended the PR.
Thanks!
Without declaring $DB as a global variable in config.php (similarly to how it is done for $CFG), the PHPUnit raises