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

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

      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.

            Unassigned Unassigned
            timhunt Tim Hunt
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:

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

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