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

    • Type: Improvement
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 3.6.7, 3.7.3, 3.8
    • Fix Version/s: None
    • Component/s: Libraries, Unit tests
    • Labels:

      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

              Assignee:
              Unassigned
              Reporter:
              timhunt Tim Hunt
              Participants:
              Component watchers:
              Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona), Víctor Déniz Falcón, Andrew Nicols, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze
              Votes:
              1 Vote for this issue
              Watchers:
              4 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