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

Make test files and test classes to match to get phpunit able to run individual files



      This is a followup of MDL-71036 (upgrade to PHPUnit 9), where given moodle's naming standards for test files and test classes, we have lost the possibility of executing phpunit by file name.

      Extracted from the summary comment:

      ... PHPUnit 9 comes with a new (double) restriction. Basically, to be able to continue running tests by name, these 2 conditions must be fulfilled (see #4105 for more information):

      a) The test file cannot have multiple test cases (we have MDL-37655 since ages ago about that).

      b) The test file and the test class name must match (this issue).

      And, while a) doesn't hurt us much (say we have only a a dozen of files needing to split), b) hurts us completely, for every test file. Because our current rules are:

      • xxxx_test.php for the files.
      • [component]_xxxx_testcase for the classname.

      And they, obviously, break the "name-matching" condition commented in b).
      Basically, there are 4 possibilities:

      1. We do nothing, won't be able to run tests by filename anymore.
      2. We modify all the file names to match the test names (aka, "lib/tests/core_moodlelib_testcase.php" will run the "core_moodlelib_testcase" testcase). Will require to change suites and other stuff (not expecting all files to be "_test.php" finished") and will make backports tricker.
      3. We modify all the test case names (aka, "lib/tests/moodlelib_test.php" will run the "moodlelib_test" testcase). Easier and backportable tests (but because of the different class name line).
      4. We invent any other new naming schema and apply for it codebase-wide.

      Again, note that this issue is only to be able to run tests by file name. Everything else (whole runs, filters, suites, custom config...) continue working perfectly.

      So, let's decide one of the (1-4) options above and go for it:

      • TODO: Perform the agreed change (if any).
      • TODO: Amend documentation about the new naming schema to follow (if any).
      • TODO: Create a new check (or sniff) to get the matching names validated. Surely with level = warning.


            stronk7 Eloy Lafuente (stronk7)
            stronk7 Eloy Lafuente (stronk7)
            3 Vote for this issue
            12 Start watching this issue


                Original Estimate - 0 minutes
                Remaining Estimate - 0 minutes
                Time Spent - 2 weeks, 4 days, 1 hour, 45 minutes
                2w 4d 1h 45m

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