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

Verify test_context_not_used unit test and fix it



    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 3.10
    • None
    • Unit tests
    • None


      This was discovered working on MDL-67673 (upgrade to PHPUnit 8.x). Note this is highly similar to MDL-69700 (happening in another place).

      The test_context_not_used() unit test is really strange, but that's normally not detected because the test expects a notice and certainly gets it.

      To reproduce it:

      1) Edit lib/tests/event_test.php, go to the test_context_not_used() method and comment the line:


      2) Run $ vendor/bin/phpunit --filter ::test_context_not_used

      3 You will get:

      There was 1 error:
      1) core_event_testcase::test_context_not_used
      Trying to get property 'instanceid' of non-object

      The points here are:

      a) Verify that really that's the notice the test is expecting, because it's a really strange one. Fix it if that's not the case.

      b) Move the exception expectation to the correct place. Note that right now the notice happens in the 1st line after the expectation and that's strange because then... what's all the remaining code about? It's not reachable (the exception happens earlier).

      And that's it. As said, the problem is masked because the test expects a notice/warning. This is just about to ensure that's the notice it is expecting and that there isn't trailing code after the notice happens.


        Issue Links



              Unassigned Unassigned
              stronk7 Eloy Lafuente (stronk7)
              Andrew Lyons, Huong Nguyen, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze
              0 Vote for this issue
              2 Start watching this issue