Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagephp
define('TOTARA_DISTRIBUTION_TEST', true);

Isolated Tests

Tests can be run in isolation (each test running in its own PHP process) by passing along the --process-isolation flag. However this will take much longer than a regular parallel test.

Adding new tests

Naming of test case classes and files

...

  • All calls to tearDown and tearDownAfterClass must call the matching parent method.

  • PHP notices/warnings/errors will not auto-convert into exceptions.
    This feature was removed from PHPUnit with no replacement, tests that rely on checking for PHP warnings were adjusted.

  • Some functions in the Mocking API have been removed.
    Functions like onConsecutiveCalls have been removed. The full list can be seen in the deprecations list.

  • testcase_autoloader, advanced_testcase and basic_testcase have been removed.
    The autoloader is no longer relevant as our tests must be named correctly. The other base testcase classes have been deprecated since Totara 14 and are now gone.

  • Assertions assertTag and assertNotTag are deprecated.
    These still exist for some legacy tests but please do not use them on any new tests.

  • Dataproviders cannot include PHP resources or closures. All objects/data returned must be serilizable.
    Isolated tests pass data between tests via the php serialize function, anything that cannot be passed through will crash tests when running in isolation.

  • Data providers must return examples in the correct format.

    A collection of an array of parameters must be returned, with each entry optionally being keyed by a unique message explaining the test case. The parameters array may also be keyed, and if it is the keys must match the testcase method signature.

    Code Block
    languagephp
    // Simple Example
    public static function my_data_provider(): array {
    	return [
    		['propA Value', 'propB Value', 'propC Value'], // Test 1
    		['propA Value', 'propB Value', 'propC Value'], // Test 2
    	];
    }
    // Named Entries
    public static function my_data_provider(): array {
    	return [
    		'data label 1' => ['propA Value', 'propB Value', 'propC Value'],
    		'data label 2' => ['propA Value', 'propB Value', 'propC Value'],
    	];
    }
    // Named Properties
    public static function my_data_provider(): array {
    	return [
    		[
    			'propA' => 'propA Value', 
    			'propB' => 'propB Value', 
    			'propC' => 'propC Value'
    		],
    		[
    			'propA' => 'propA Value', 
    			'propB' => 'propB Value', 
    			'propC' => 'propC Value'
    		],
    	];
    }
    // Named & Labelled
    public static function my_data_provider(): array {
    	return [
    		'data label 1' => [
    			'propA' => 'propA Value', 
    			'propB' => 'propB Value', 
    			'propC' => 'propC Value'
    		],
    		'data label 2' => [
    			'propA' => 'propA Value', 
    			'propB' => 'propB Value', 
    			'propC' => 'propC Value'
    		],
    	];
    }

...