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

PHP Unit can skips test when other files are required

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 2.6
    • Fix Version/s: 2.6
    • Component/s: Unit tests
    • Labels:
      None
    • Testing Instructions:
      Hide
      1. Run the Unit Tests.
      2. Run a test file with inclusion at the top of the file using the command: phpunit <name of the file>

      Do not use the name of the class in the command

      More testing notes:

      This only applies to tests relying on autoloaded classes.

      E.g.

      Edit lib/tests/text_test.php

      Add this to the top of the file (after the internal check):

       require_once(dirname(dirname(__FILE__)) . 'csvlib.class.php');
      

      Now run:

      phpunit lib/tests/text_test.php
      

      Show
      Run the Unit Tests. Run a test file with inclusion at the top of the file using the command: phpunit <name of the file> Do not use the name of the class in the command More testing notes: This only applies to tests relying on autoloaded classes. E.g. Edit lib/tests/text_test.php Add this to the top of the file (after the internal check): require_once(dirname(dirname(__FILE__)) . 'csvlib.class.php'); Now run: phpunit lib/tests/text_test.php
    • Affected Branches:
      MOODLE_26_STABLE
    • Fixed Branches:
      MOODLE_26_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      MDL-40561-master

      Description

      Due to a new logic in guessing the class containing the unit tests, if a file is included before a testcase, then the testcase class can be missed. Therefore resulting in nothing being tested.

      // admin/tool/uploadcourse/tests/processor_test.php
      require_once($CFG->libdir . '/csvlib.class.php');
       
      class tool_uploadcourse_processor_testcase extends advanced_testcase {
       
          public function test_something() {
               // Was never called.
          }
       
      }
      

        Attachments

          Activity

            People

            Assignee:
            fred Frédéric Massart
            Reporter:
            fred Frédéric Massart
            Peer reviewer:
            Petr Skoda
            Integrator:
            Damyon Wiese
            Tester:
            Michael de Raadt
            Participants:
            Component watchers:
            Andrew Nicols, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Fix Release Date:
              18/Nov/13