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

Verify test_context_not_used unit test and fix it

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • 4.2.7, 4.3.4
    • 3.10
    • Unit tests

      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.

            stronk7 Eloy Lafuente (stronk7)
            stronk7 Eloy Lafuente (stronk7)
            Andrew Lyons Andrew Lyons
            Sara Arjona (@sarjona) Sara Arjona (@sarjona)
            CiBoT CiBoT
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 5 hours, 19 minutes
                5h 19m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.