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

Verify test_context_not_used unit test and fix it

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Minor
    • None
    • 3.10
    • Unit tests
    • None
    • MOODLE_310_STABLE

    Description

      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:

      $this->expectException(\PHPUnit\Framework\Error\Notice::class);
      

      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.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              stronk7 Eloy Lafuente (stronk7)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: