Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 401 and 403]

Support library for the cache PHPUnit tests. This file is part of Moodle's cache API, affectionately called MUC. It contains the components that are requried in order to use caching.

Copyright: 2012 Sam Hemelryk
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 588 lines (20 kb)
Included or required:0 times
Referenced: 9 times
Includes or requires: 1 file
 cache/tests/fixtures/cachestore_file_with_ttl_wrappers.php

Defines 9 classes

cache_config_testing:: (10 methods):
  create_default_configuration()
  get_config_file_path()
  phpunit_add_definition()
  phpunit_remove_definition()
  phpunit_remove_stores()
  phpunit_add_file_store()
  phpunit_add_session_store()
  phpunit_add_definition_mapping()
  get_site_identifier()
  config_file_exists()

cache_phpunit_dummy_object:: (3 methods):
  __construct()
  prepare_to_cache()
  wake_from_cache()

cache_phpunit_dummy_datasource:: (3 methods):
  get_instance_for_cache()
  load_for_cache()
  load_many_for_cache()

cache_phpunit_application:: (4 methods):
  phpunit_get_store_class()
  phpunit_get_store_implements()
  phpunit_static_acceleration_get()
  phpunit_static_acceleration_purge()

cache_phpunit_session:: (5 methods):
  phpunit_get_store_class()
  phpunit_get_store_implements()
  phpunit_get_key_prefix()
  phpunit_mockup_session_id()
  set_session_id()

cache_phpunit_request:: (2 methods):
  phpunit_get_store_class()
  phpunit_get_store_implements()

cache_phpunit_dummy_overrideclass:: (0 methods):

cache_phpunit_factory:: (1 method):
  phpunit_disable()

cache_phpunit_cache:: (1 method):
  simulate_new_request()


Class: cache_config_testing  - X-Ref

Override the default cache configuration for our own maniacal purposes.

This class was originally named cache_config_phpunittest but was renamed in 2.9
because it is used for both unit tests and acceptance tests.

create_default_configuration($forcesave = false)   X-Ref
Creates the default configuration and saves it.

This function calls config_save, however it is safe to continue using it afterwards as this function should only ever
be called when there is no configuration file already.

param: bool $forcesave If set to true then we will forcefully save the default configuration file.
return: true|array Returns true if the default configuration was successfully created.

get_config_file_path()   X-Ref
Returns the expected path to the configuration file.

We override this function to add handling for $CFG->altcacheconfigpath.
We want to support it so that people can run unit tests against alternative cache setups.
However we don't want to ever make changes to the file at $CFG->altcacheconfigpath so we
always use dataroot and copy the alt file there as required.

return: string The absolute path

phpunit_add_definition($area, array $properties, $addmapping = true)   X-Ref
Adds a definition to the stack

param: string $area
param: array $properties
param: bool $addmapping By default this method adds a definition and a mapping for that definition. You can

phpunit_remove_definition($name)   X-Ref
Removes a definition.

param: string $name

phpunit_remove_stores()   X-Ref
Removes the configured stores so that there are none available.


phpunit_add_file_store(string $name, bool $nativettl = true)   X-Ref
Forcefully adds a file store.

You can turn off native TTL support if you want a way to test TTL wrapper objects.

param: string $name
param: bool $nativettl If false, uses fixture that turns off native TTL support

phpunit_add_session_store($name)   X-Ref
Forcefully adds a session store.

param: string $name

phpunit_add_definition_mapping($definition, $store, $sort)   X-Ref
Forcefully injects a definition => store mapping.

This function does no validation, you should only be calling if it you know
exactly what to expect.

param: string $definition
param: string $store
param: int $sort

get_site_identifier()   X-Ref
Overrides the default site identifier used by the Cache API so that we can be sure of what it is.

return: string

config_file_exists()   X-Ref
Checks if the configuration file exists.

return: bool True if it exists

Class: cache_phpunit_dummy_object  - X-Ref

Dummy object for testing cacheable object interface and interaction

Wake from cache needs specific testing at times to ensure that during multiple
cache get() requests it's possible to verify that it's getting woken each time.

__construct($property1, $property2, $propertytime = null)   X-Ref
Constructor

param: string $property1
param: string $property2

prepare_to_cache()   X-Ref
Prepares this object for caching

return: array

wake_from_cache($data)   X-Ref
Returns this object from the cache

param: array $data
return: cache_phpunit_dummy_object

Class: cache_phpunit_dummy_datasource  - X-Ref

Dummy data source object for testing data source interface and implementation

get_instance_for_cache(cache_definition $definition)   X-Ref
Returns an instance of this object for use with the cache.

param: cache_definition $definition
return: cache_phpunit_dummy_datasource

load_for_cache($key)   X-Ref
Loads a key for the cache.

param: string $key
return: string

load_many_for_cache(array $keys)   X-Ref
Loads many keys for the cache

param: array $keys
return: array

Class: cache_phpunit_application  - X-Ref

PHPUnit application cache loader.

Used to expose things we could not otherwise see within an application cache.

phpunit_get_store_class()   X-Ref
Returns the class of the store immediately associated with this cache.

return: string

phpunit_get_store_implements()   X-Ref
Returns all the interfaces the cache store implements.

return: array

phpunit_static_acceleration_get($key)   X-Ref
Returns the given key directly from the static acceleration array.

param: string $key
return: false|mixed

phpunit_static_acceleration_purge()   X-Ref
Purges only the static acceleration while leaving the rest of the store in tack.

Used for behaving like you have loaded 2 pages, and reset static while the backing store
still contains all the same data.


Class: cache_phpunit_session  - X-Ref

PHPUnit session cache loader.

Used to expose things we could not otherwise see within an session cache.

phpunit_get_store_class()   X-Ref
Returns the class of the store immediately associated with this cache.

return: string

phpunit_get_store_implements()   X-Ref
Returns all the interfaces the cache store implements.

return: array

phpunit_get_key_prefix()   X-Ref
Provide access to the {@link cache_session::get_key_prefix()} method.

return: string

phpunit_mockup_session_id($sessionid)   X-Ref
Allows to inject the session identifier.

param: string $sessionid

set_session_id()   X-Ref
Override the parent behaviour so that it does not need the actual session_id() call.


Class: cache_phpunit_request  - X-Ref

PHPUnit request cache loader.

Used to expose things we could not otherwise see within an request cache.

phpunit_get_store_class()   X-Ref
Returns the class of the store immediately associated with this cache.

return: string

phpunit_get_store_implements()   X-Ref
Returns all the interfaces the cache store implements.

return: array

Class: cache_phpunit_dummy_overrideclass  - X-Ref

Dummy overridden cache loader class that we can use to test overriding loader functionality.

Class: cache_phpunit_factory  - X-Ref

Cache PHPUnit specific factory.

phpunit_disable()   X-Ref
Exposes the cache_factory's disable method.

Perhaps one day that method will be made public, for the time being it is protected.

Class: cache_phpunit_cache  - X-Ref

Cache PHPUnit specific Cache helper.

simulate_new_request()   X-Ref
Make the changes which simulate a new request within the cache.
This essentially resets currently held static values in the class, and increments the current timestamp.