Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-82142 Various problems with PHPUnit's coverage annotations
  3. MDL-82148

Remove multiple uses of @coversDefaultClass in tests

XMLWordPrintable

    • MOODLE_401_STABLE, MOODLE_402_STABLE, MOODLE_403_STABLE, MOODLE_404_STABLE, MOODLE_405_STABLE
    • MOODLE_401_STABLE, MOODLE_402_STABLE, MOODLE_403_STABLE, MOODLE_404_STABLE
    • MDL-82148_401
    • MDL-82148_403
    • MDL-82148_404
    • Hide

      Requirements

      You need to have one of the php-xdebug or php-pcov extensions installed and enabled in order to capture coverage. If not available, PHPUnit execution will show you a warning about that ("Warning: No code coverage driver available").

      Sanity check

      1. Run this command in moodle dir root:
        find . -name "*_test.php" | xargs grep -c @coversDefaultClas | grep -v ':[01]$'
      2. Verify that it reruns no occurrences.

      Running the tests with coverage enabled

      1. Init PHPUnit.
      2. For each of the test files modified in this issue (list of files at the end), run the following command:
        vendor/bin/phpunit -v --coverage-text path/to/test/file
      3. Verify the the test execution ends "ok".
      4. Verify that you get some textual output, with a summary a list of classes and some other information (details are not important).
      5. Important, verify that there isn't any warning or error about incorrect covers/coversclass annotations.

      List of files modified:

      • lib/tests/http_client_test.php (only 402_STABLE and up)
      • mod/quiz/tests/quiz_question_restore_test.php
      • privacy/tests/legacy_polyfill_test.php
      • question/bank/editquestion/tests/external/update_question_version_status_test.php
      Show
      Requirements You need to have one of the php-xdebug or php-pcov extensions installed and enabled in order to capture coverage. If not available, PHPUnit execution will show you a warning about that ( "Warning: No code coverage driver available" ). Sanity check Run this command in moodle dir root: find . -name "*_test.php" | xargs grep -c @coversDefaultClas | grep -v ': [01] $' Verify that it reruns no occurrences. Running the tests with coverage enabled Init PHPUnit. For each of the test files modified in this issue (list of files at the end), run the following command: vendor/bin/phpunit -v --coverage-text path/to/test/file Verify the the test execution ends "ok". Verify that you get some textual output, with a summary a list of classes and some other information (details are not important). Important, verify that there isn't any warning or error about incorrect covers/coversclass annotations. List of files modified: lib/tests/http_client_test.php (only 402_STABLE and up) mod/quiz/tests/quiz_question_restore_test.php privacy/tests/legacy_polyfill_test.php question/bank/editquestion/tests/external/update_question_version_status_test.php

      It has been detected that we have a few (3-4) cases where the same class has multiple @coversDefaultClass declarations.

      That's wrong, and leads to PHPUnit with code coverage to stop with error.

      That annotation is only a shortcut/default to be applied to any test covering methods and to avoid to type the FQN class name all the time. Just that.

      So this issue is about to review those cases, changing them to use the required @covers annotations and only leaving one (or zero) @coversDefaultClass uses on each test.

      Related, https://github.com/moodlehq/moodle-cs/issues/166 has been created to detect this problem in the future from moodle-cs.

            stronk7 Eloy Lafuente (stronk7)
            stronk7 Eloy Lafuente (stronk7)
            Paul Holden Paul Holden
            Simey Lameze Simey Lameze
            Kim Jared Lucas Kim Jared Lucas
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 3 hours, 13 minutes
                3h 13m

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