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

Need a better way to access PHPUNIT_TEST, CLI_SCRIPT, etc, so they can be mocked in unit tests

    XMLWordPrintable

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 3.6.7, 3.7.3, 3.8
    • None
    • Libraries, Unit tests

    Description

      This was discovered while working on MDL-64531, where we wanted a PHPUNIT test to test the behaviour of a function with AJAX_SCRIPT true and false.

      Also, it is the case that wherever we access these constants in the code, we have duplicated logic like (defined('PHPUNIT_TEST') && PHPUNIT_TEST).

      I suggest we add a wrapper for this, like:

      core_script_type::is('PHPUNIT_TEST')

      This should reduce duplicated logic, and allow these things to be overridden during unit tests.

      As well as coding this new mechanism, all the existing reference to the bare constants should be updated.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              timhunt Tim Hunt
              David Woloszyn, Huong Nguyen, Jake Dallimore, Meirza, Michael Hawkins, Raquel Ortega, Safat Shahin, Stevani Andolo
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

                  Estimated:
                  Original Estimate - 0 minutes
                  0m
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 1 minute
                  1m