Moodle APIs  3.8
Moodle 3.8.6 (Build: 20201109)
Static Public Member Functions | Static Public Attributes | Static Protected Member Functions | Static Protected Attributes | List of all members
phpunit_util Class Reference
Inheritance diagram for phpunit_util:
testing_util

Static Public Member Functions

static bootstrap_init ()
 Called during bootstrap only!
 
static bootstrap_moodle_info ()
 Print some Moodle related info to console.
 
static build_component_config_files ()
 Builds phpunit.xml files for all components using defaults from /phpunit.xml.dist. More...
 
static build_config_file ()
 Builds dirroot/phpunit.xml and dataroot/phpunit/webrunner.xml files using defaults from /phpunit.xml.dist. More...
 
static call_internal_method ($object, $methodname, array $params=array(), $classname)
 Helper function to call a protected/private method of an object using reflection. More...
 
static clean_tables_updated_by_scenario_list ()
 Delete tablesupdatedbyscenario file. More...
 
static debugging_triggered ($message, $level, $from)
 To be called from debugging() only. More...
 
static display_debugging_messages ($return=false)
 Prints out any debug messages accumulated during test execution. More...
 
static drop_site ($displayprogress=false)
 Drop all test site data. More...
 
static event_triggered (\core\event\base $event)
 To be called from core\event\base only! More...
 
static get_data_generator ()
 Get data generator. More...
 
static get_dataroot ()
 Return the dataroot. More...
 
static get_debugging_messages ()
 Returns all debugging messages triggered during test. More...
 
static get_environment ()
 Return list of environment versions on which tests will run. More...
 
static get_git_hash ()
 Try to get current git hash of the Moodle in $CFG->dirroot. More...
 
static get_global_backup ($name)
 Returns original state of global variable. More...
 
static get_originaldatafilesjson ()
 Return the name of the JSON file containing the init filenames. More...
 
static get_sequencenames ()
 Returns the names of sequences for each autoincrementing id field in all standard tables. More...
 
static get_site_info ()
 Gets a text-based site version description. More...
 
static get_tablestructure ()
 Returns structure of all tables right after installation. More...
 
static initialise_cfg ()
 Load global $CFG;.
 
static install_site ()
 Perform a fresh test site installation. More...
 
static is_in_isolated_process ()
 Whether the current process is an isolated test process. More...
 
static is_redirecting_events ()
 Are events redirected to some sink? More...
 
static is_redirecting_messages ()
 Are messages redirected to some sink? More...
 
static is_redirecting_phpmailer ()
 Are messages for phpmailer redirected to some sink? More...
 
static is_test_data_updated ()
 Returns whether test database and dataroot were created using the current version codebase. More...
 
static is_test_site ()
 Does this site (db and dataroot) appear to be used for production? We try very hard to prevent accidental damage done to production servers!! More...
 
static message_sent ($message)
 To be called from messagelib.php only! More...
 
static phpmailer_sent ($message)
 To be called from messagelib.php only! More...
 
static reset_all_data ($detectchanges=false)
 Reset contents of all database tables to initial values, reset caches, etc. More...
 
static reset_all_database_sequences (array $empties=null)
 Reset all database sequences to initial values. More...
 
static reset_database ()
 Reset all database tables to default values. More...
 
static reset_dataroot ()
 Purge dataroot directory. More...
 
static reset_debugging ()
 Resets the list of debugging messages.
 
static reset_updated_table_list ()
 Reset updated table list. More...
 
static run_all_adhoc_tasks ()
 Executes all adhoc tasks in the queue. More...
 
static set_dataroot ($dataroot)
 Set the dataroot. More...
 
static set_table_modified_by_sql ($sql)
 Set state of modified tables. More...
 
static start_event_redirection ()
 Start event redirection. More...
 
static start_message_redirection ()
 Start message redirection. More...
 
static start_phpmailer_redirection ()
 Start phpmailer redirection. More...
 
static stop_event_redirection ()
 End event redirection. More...
 
static stop_message_redirection ()
 End message redirection. More...
 
static stop_phpmailer_redirection ()
 End phpmailer redirection. More...
 
static testing_ready_problem ()
 Is this site initialised to run unit tests? More...
 

Static Public Attributes

static int $lastdbwrites = null
 last value of db writes counter, used for db resetting
 
static array $tableupdated = array()
 list of updated tables.
 

Static Protected Member Functions

static drop_database ($displayprogress=false)
 Drop the whole test database. More...
 
static drop_dataroot ()
 Drops the test framework dataroot.
 
static get_coverage_info (string $fulldir)
 Get the phpunit_coverage_info for the specified plugin or subsystem directory. More...
 
static get_filter_config (array $whitelists, array $excludelists)
 Get the filter config for the supplied whitelist and excludelist configuration. More...
 
static get_framework ()
 Returns the testing framework name. More...
 
static get_locale_name ()
 Gets the name of the locale for testing environment (Australian English) depending on platform environment. More...
 
static get_tabledata ()
 Returns contents of all tables right after installation. More...
 
static get_tables_updated_by_scenario_list_path ()
 Returns the path to the file which holds list of tables updated in scenario. More...
 
static guess_unmodified_empty_tables ()
 Returns list of tables that are unmodified and empty. More...
 
static pad (string $string, int $level)
 Pad the supplied string with $level levels of indentation. More...
 
static save_original_data_files ()
 Save the list of the original dataroot files into a json file.
 
static skip_original_data_files ($utilclassname)
 Skip the original dataroot files to not been reset. More...
 
static store_database_state ()
 Stores the status of the database. More...
 
static store_versions_hash ()
 Stores the version hash in both database and dataroot.
 

Static Protected Attributes

static array $datarootskipondrop = array('.', '..', 'lock', 'webrunner.xml')
 Files to skip when dropping dataroot folder.
 
static array $datarootskiponreset = array('.', '..', 'phpunittestdir.txt', 'phpunit', '.htaccess')
 Files to skip when resetting dataroot folder.
 
static array $debuggings = array()
 list of debugging messages triggered during the last test execution
 
static phpunit_message_sink $eventsink = null
 alternative target for moodle messaging
 
static testing_data_generator $generator = null
 
static array $globals = array()
 An array of original globals, restored after each test.
 
static phpunit_message_sink $messagesink = null
 alternative target for moodle messaging
 
static phpunit_phpmailer_sink $phpmailersink = null
 alternative target for phpmailer messaging
 
static array $sequencenames = null
 original structure of all database tables
 
static int $sequencenextstartingid = null
 next sequence value for a single test cycle.
 
static array $tabledata = null
 original content of all database tables
 
static array $tablestructure = null
 original structure of all database tables
 
static string $versionhash = null
 current version hash from php files
 

Member Function Documentation

◆ build_component_config_files()

static phpunit_util::build_component_config_files ( )
static

Builds phpunit.xml files for all components using defaults from /phpunit.xml.dist.

Return values
void,stopsif can not write files

◆ build_config_file()

static phpunit_util::build_config_file ( )
static

Builds dirroot/phpunit.xml and dataroot/phpunit/webrunner.xml files using defaults from /phpunit.xml.dist.

Return values
booltrue means main config file created, false means only dataroot file created

◆ call_internal_method()

static phpunit_util::call_internal_method (   $object,
  $methodname,
array  $params = array(),
  $classname 
)
static

Helper function to call a protected/private method of an object using reflection.

Example 1. Calling a protected object method: $result = call_internal_method($myobject, 'method_name', [$param1, $param2], '\my\namespace\myobjectclassname');

Example 2. Calling a protected static method: $result = call_internal_method(null, 'method_name', [$param1, $param2], '\my\namespace\myclassname');

Parameters
object | null$objectthe object on which to call the method, or null if calling a static method.
string$methodnamethe name of the protected/private method.
array$paramsthe array of function params to pass to the method.
string$classnamethe fully namespaced name of the class the object was created from (base in the case of mocks), or the name of the static class when calling a static method.
Return values
mixedthe respective return value of the method.

◆ clean_tables_updated_by_scenario_list()

static testing_util::clean_tables_updated_by_scenario_list ( )
staticinherited

Delete tablesupdatedbyscenario file.

This should be called before suite, to ensure full db reset.

◆ debugging_triggered()

static phpunit_util::debugging_triggered (   $message,
  $level,
  $from 
)
static

To be called from debugging() only.

Parameters
string$message
int$level
string$from

◆ display_debugging_messages()

static phpunit_util::display_debugging_messages (   $return = false)
static

Prints out any debug messages accumulated during test execution.

Parameters
bool$returntrue to return the messages or false to print them directly. Default false.
Return values
bool|stringfalse if no debug messages, true if debug triggered or string of messages

◆ drop_database()

static testing_util::drop_database (   $displayprogress = false)
staticprotectedinherited

Drop the whole test database.

Parameters
bool$displayprogress

◆ drop_site()

static phpunit_util::drop_site (   $displayprogress = false)
static

Drop all test site data.

Note: To be used from CLI scripts only.

Parameters
bool$displayprogressif true, this method will echo progress information.
Return values
voidmay terminate execution with exit code

◆ event_triggered()

static phpunit_util::event_triggered ( \core\event\base  $event)
static

To be called from core\event\base only!

Parameters
core\event\base$eventrecord from event_read table
Return values
booltrue means send event, false means event "sent" to sink.

◆ get_coverage_info()

static phpunit_util::get_coverage_info ( string  $fulldir)
staticprotected

Get the phpunit_coverage_info for the specified plugin or subsystem directory.

Parameters
string$fulldirThe directory to find the coverage info file in.
Return values
phpunit_coverage_info

◆ get_data_generator()

static testing_util::get_data_generator ( )
staticinherited

Get data generator.

Return values
testing_data_generator

◆ get_dataroot()

static testing_util::get_dataroot ( )
staticinherited

Return the dataroot.

It's useful when mocking the dataroot when unit testing this class itself.

Return values
stringthe dataroot.

◆ get_debugging_messages()

static phpunit_util::get_debugging_messages ( )
static

Returns all debugging messages triggered during test.

Return values
arraywith instances having message, level and stacktrace property.

◆ get_environment()

static testing_util::get_environment ( )
staticinherited

Return list of environment versions on which tests will run.

Environment includes:

  • moodleversion
  • phpversion
  • dbtype
  • dbversion
  • os
Return values
array

◆ get_filter_config()

static phpunit_util::get_filter_config ( array  $whitelists,
array  $excludelists 
)
staticprotected

Get the filter config for the supplied whitelist and excludelist configuration.

Parameters
array[]$whitelistsThe list of files/folders in the whitelist.
array[]$excludelistsThe list of files/folders in the excludelist.
Return values
string

◆ get_framework()

static testing_util::get_framework ( )
staticfinalprotectedinherited

Returns the testing framework name.

Return values
string

◆ get_git_hash()

static testing_util::get_git_hash ( )
staticinherited

Try to get current git hash of the Moodle in $CFG->dirroot.

Return values
stringnull if unknown, sha1 hash if known

◆ get_global_backup()

static phpunit_util::get_global_backup (   $name)
static

Returns original state of global variable.

Parameters
string$name
Return values
mixed

◆ get_locale_name()

static phpunit_util::get_locale_name ( )
staticprotected

Gets the name of the locale for testing environment (Australian English) depending on platform environment.

Return values
stringthe locale name.

◆ get_originaldatafilesjson()

static testing_util::get_originaldatafilesjson ( )
staticinherited

Return the name of the JSON file containing the init filenames.

Return values
string

◆ get_sequencenames()

static testing_util::get_sequencenames ( )
staticinherited

Returns the names of sequences for each autoincrementing id field in all standard tables.

Return values
array::$table,=>$sequencename

◆ get_site_info()

static testing_util::get_site_info ( )
staticinherited

Gets a text-based site version description.

Return values
stringThe site info

◆ get_tabledata()

static testing_util::get_tabledata ( )
staticprotectedinherited

Returns contents of all tables right after installation.

Return values
array::$table,=>$records

◆ get_tables_updated_by_scenario_list_path()

static testing_util::get_tables_updated_by_scenario_list_path ( )
staticfinalprotectedinherited

Returns the path to the file which holds list of tables updated in scenario.

Return values
string

◆ get_tablestructure()

static testing_util::get_tablestructure ( )
staticinherited

Returns structure of all tables right after installation.

Return values
array::$table,=>$records

◆ guess_unmodified_empty_tables()

static testing_util::guess_unmodified_empty_tables ( )
staticprotectedinherited

Returns list of tables that are unmodified and empty.

Return values
arrayof table names, empty if unknown

◆ install_site()

static phpunit_util::install_site ( )
static

Perform a fresh test site installation.

Note: To be used from CLI scripts only.

Return values
voidmay terminate execution with exit code

◆ is_in_isolated_process()

static phpunit_util::is_in_isolated_process ( )
static

Whether the current process is an isolated test process.

Return values
bool

◆ is_redirecting_events()

static phpunit_util::is_redirecting_events ( )
static

Are events redirected to some sink?

Note: to be called from core\event\base only!

Return values
bool

◆ is_redirecting_messages()

static phpunit_util::is_redirecting_messages ( )
static

Are messages redirected to some sink?

Note: to be called from messagelib.php only!

Return values
bool

◆ is_redirecting_phpmailer()

static phpunit_util::is_redirecting_phpmailer ( )
static

Are messages for phpmailer redirected to some sink?

Note: to be called from moodle_phpmailer.php only!

Return values
bool

◆ is_test_data_updated()

static testing_util::is_test_data_updated ( )
staticinherited

Returns whether test database and dataroot were created using the current version codebase.

Return values
bool

◆ is_test_site()

static testing_util::is_test_site ( )
staticinherited

Does this site (db and dataroot) appear to be used for production? We try very hard to prevent accidental damage done to production servers!!

Return values
bool

◆ message_sent()

static phpunit_util::message_sent (   $message)
static

To be called from messagelib.php only!

Parameters
stdClass$messagerecord from messages table
Return values
booltrue means send message, false means message "sent" to sink.

◆ pad()

static phpunit_util::pad ( string  $string,
int  $level 
)
staticprotected

Pad the supplied string with $level levels of indentation.

Parameters
string$stringThe string to pad
int$levelThe number of levels of indentation to pad
Return values
string

◆ phpmailer_sent()

static phpunit_util::phpmailer_sent (   $message)
static

To be called from messagelib.php only!

Parameters
stdClass$messagerecord from messages table
Return values
booltrue means send message, false means message "sent" to sink.

◆ reset_all_data()

static phpunit_util::reset_all_data (   $detectchanges = false)
static

Reset contents of all database tables to initial values, reset caches, etc.

Note: this is relatively slow (cca 2 seconds for pg and 7 for mysql) - please use with care!

Parameters
bool$detectchangestrue - changes in global state and database are reported as errors false - no errors reported null - only critical problems are reported as errors
Return values
void

◆ reset_all_database_sequences()

static testing_util::reset_all_database_sequences ( array  $empties = null)
staticinherited

Reset all database sequences to initial values.

Parameters
array$emptiestables that are known to be unmodified and empty
Return values
void

◆ reset_database()

static phpunit_util::reset_database ( )
static

Reset all database tables to default values.

Return values
booltrue if reset done, false if skipped

Reimplemented from testing_util.

◆ reset_dataroot()

static testing_util::reset_dataroot ( )
staticinherited

Purge dataroot directory.

Return values
void

◆ reset_updated_table_list()

static testing_util::reset_updated_table_list ( )
staticinherited

Reset updated table list.

This should be done after every reset.

◆ run_all_adhoc_tasks()

static phpunit_util::run_all_adhoc_tasks ( )
static

Executes all adhoc tasks in the queue.

Useful for testing asynchronous behaviour.

Return values
void

◆ set_dataroot()

static testing_util::set_dataroot (   $dataroot)
staticinherited

Set the dataroot.

It's useful when mocking the dataroot when unit testing this class itself.

Parameters
string$datarootthe dataroot of the test framework.

◆ set_table_modified_by_sql()

static testing_util::set_table_modified_by_sql (   $sql)
staticinherited

Set state of modified tables.

Parameters
string$sqlsql which is updating the table.

◆ skip_original_data_files()

static testing_util::skip_original_data_files (   $utilclassname)
staticprotectedinherited

Skip the original dataroot files to not been reset.

Parameters
string$utilclassnamethe util class name..

◆ start_event_redirection()

static phpunit_util::start_event_redirection ( )
static

Start event redirection.

Note: Do not call directly from tests, use $sink = $this->redirectEvents() instead.

Return values
phpunit_event_sink

◆ start_message_redirection()

static phpunit_util::start_message_redirection ( )
static

Start message redirection.

Note: Do not call directly from tests, use $sink = $this->redirectMessages() instead.

Return values
phpunit_message_sink

◆ start_phpmailer_redirection()

static phpunit_util::start_phpmailer_redirection ( )
static

Start phpmailer redirection.

Note: Do not call directly from tests, use $sink = $this->redirectEmails() instead.

Return values
phpunit_phpmailer_sink

◆ stop_event_redirection()

static phpunit_util::stop_event_redirection ( )
static

End event redirection.

Note: Do not call directly from tests, use $sink->close() instead.

◆ stop_message_redirection()

static phpunit_util::stop_message_redirection ( )
static

End message redirection.

Note: Do not call directly from tests, use $sink->close() instead.

◆ stop_phpmailer_redirection()

static phpunit_util::stop_phpmailer_redirection ( )
static

End phpmailer redirection.

Note: Do not call directly from tests, use $sink->close() instead.

◆ store_database_state()

static testing_util::store_database_state ( )
staticprotectedinherited

Stores the status of the database.

Serializes the contents and the structure and stores it in the test framework space in dataroot

◆ testing_ready_problem()

static phpunit_util::testing_ready_problem ( )
static

Is this site initialised to run unit tests?

Return values
intarray errorcode=>message, 0 means ok

The documentation for this class was generated from the following file: