jpahullo / moodle-tool_mergeusers

Merge users script for Moodle

Home Page:https://moodle.org/plugins/view.php?plugin=tool_mergeusers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

phpunit test failure on 3.9

danmarsden opened this issue · comments

I dropped this into a 3.9 site today and ran through unit tests and got the following failure:

  1. core_moodlelib_testcase::test_generate_confirmation_link_with_custom_admin
    Unexpected debugging() call detected.
    Debugging: Invalid 'includefile' detected in /var/www/html/admin/tool/mergeusers/db/events.php observer definition
  • line 287 of /lib/classes/event/manager.php: call to debugging()
  • line 230 of /lib/classes/event/manager.php: call to core\event\manager::add_observers()
  • line 103 of /lib/classes/event/manager.php: call to core\event\manager::init_all_observers()
  • line 75 of /lib/classes/event/manager.php: call to core\event\manager::process_buffers()
  • line 834 of /lib/classes/event/base.php: call to core\event\manager::dispatch()
  • line 262 of /lib/testing/generator/data_generator.php: call to core\event\base->trigger()
  • line 3627 of /lib/tests/moodlelib_test.php: call to testing_data_generator->create_user()
  • line 1154 of /vendor/phpunit/phpunit/src/Framework/TestCase.php: call to core_moodlelib_testcase->test_generate_confirmation_link_with_custom_admin()
  • line 842 of /vendor/phpunit/phpunit/src/Framework/TestCase.php: call to PHPUnit\Framework\TestCase->runTest()
  • line 80 of /lib/phpunit/classes/advanced_testcase.php: call to PHPUnit\Framework\TestCase->runBare()
  • line 693 of /vendor/phpunit/phpunit/src/Framework/TestResult.php: call to advanced_testcase->runBare()
  • line 796 of /vendor/phpunit/phpunit/src/Framework/TestCase.php: call to PHPUnit\Framework\TestResult->run()
  • line 746 of /vendor/phpunit/phpunit/src/Framework/TestSuite.php: call to PHPUnit\Framework\TestCase->run()
  • line 746 of /vendor/phpunit/phpunit/src/Framework/TestSuite.php: call to PHPUnit\Framework\TestSuite->run()
  • line 746 of /vendor/phpunit/phpunit/src/Framework/TestSuite.php: call to PHPUnit\Framework\TestSuite->run()
  • line 652 of /vendor/phpunit/phpunit/src/TextUI/TestRunner.php: call to PHPUnit\Framework\TestSuite->run()
  • line 206 of /vendor/phpunit/phpunit/src/TextUI/Command.php: call to PHPUnit\TextUI\TestRunner->doRun()
  • line 162 of /vendor/phpunit/phpunit/src/TextUI/Command.php: call to PHPUnit\TextUI\Command->run()
  • line 61 of /vendor/phpunit/phpunit/phpunit: call to PHPUnit\TextUI\Command::main()

Thank you @danmarsden for contributing with feedback!

We'll take a look at that, as soon as we can.

Thanks!

I had a quick look to see if using $CFG->admin might work instead of hardcoding "/admin/" but that didn't help - you might need to restructure it so that the "callback" points to an autoloaded class function eg "callback" => "tool_mergeusers\events\keptusers::unsuspend"

then you don't need the includepath at all.

Oh! Nice! For taking care of it! This will help for sure!

The path just needs that first slash removed and it seems to work

Hi @jpahullo , would you be able to look at Kristian's proposed PR when you have time? Thanks

Hi @jpahullo , I had a closer look at the issue. I don't believe kristian's fix would solve the issue as in lib/classes/event/manager.php:285, this line will trim the leading forward slash anyway.

$observer['includefile'] = $CFG->dirroot . '/' . ltrim($observer['includefile'], '/');

The actual cause of the error is a little more gnarly. It's to do with the core test test_generate_confirmation_link_with_custom_admin redefining $CFG->admin to a non-real directory, which means the includefile gets corrupted with the fake directory. I believe the issue only surfaced in Moodle 3.9 due to the tracker MDL-68333 testing: trigger user_created event in user generator causing the mergeusers events to now be triggered.

I believe that Dan's suggestion of moving the observer functions into autoloaded classes is the simplest solution to bypass the error. I've created a PR with these changes.

#187

Hi @jpahullo
Have you had a chance to have a look at the pull request #187
It seems to be working fine.
Cheers

Hi all!

Sorry for the late answer. My spare time is very scarce lastly with my little daughter.

Thank you for the thread and feedback. Thanks also for the contribution. It's great!

I've just revisited the PR with some comments. Do you think you could consider my comments and update the PR please?

Thank you again.