Test helpers: Difference between revisions

From Sunhill Framework Documentation
No edit summary
+getField()
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
{{Incomplete}}
{{Incomplete}}
== getField() ==
== getField($loader, $fieldname = null) ==
A helper to access a subfield of the field $loader.
 
=== Empty $fieldname ===
When fieldname is empty $load is returned
 
Example:
$test = 10;
getField($test); // Returns 10;
 
=== $fieldname is a string ===
When $fieldname is a string, then a member of load with this name is returned
 
Example:
$test = new StdClass();
$test->member = 'ABC';
getField($test, 'member'); // Returns 'ABC';
 
=== $fieldname is a array index ===
When $fieldname is a string containing a array index (like field[index]) this index is returned.
 
Example:
$test = [1,2,3];
getField($test,'[1]'); // Returns 2
 
=== $fieldname is a double array index ===
When $fieldname is a string containing a double array index (like field[index][index2]) this index is returned.
 
Example:
$test = [[1,2,3],[4,5,6][7,8,9]];
getField($test,'[1][1]'); // Returns 5
 
=== $fieldname is a arrowed string ===
When $fieldname is a string containing an arrow (like field->subfield) the subfield is returned.
 
Example:
$test = new StdClass();
$subfield = new StdClass();
$subfield->member = 'ABC';
$test->subfield = $subfield;
getField($test, 'subfield->member'); // Returns 'ABC';
 
=== $fieldname is a value with array index ===
When $fieldname is a string containing an field with array index (like field[index]) this index is returned.
 
Example:
$test = new StdClass();
$array = [1,2,3];
$test->subfield = $array;
getField($test,'subfield[1]'); // Returns 2
 
=== $fieldname is a double array index ===
When $fieldname is a string containing a double array index (like field[index][index2]) this index is returned.
 
Example:
$test = new StdClass();
$array = [[1,2,3],[4,5,6][7,8,9]];
$test->subfield = $array;
getField($test,'subfield[1][1]'); // Returns 5


== invokeMethod(object &$object, string $methodName, array $parameters = array()) ==
== invokeMethod(object &$object, string $methodName, array $parameters = array()) ==
Line 17: Line 75:
== checkArrays(array $expect, array $test): bool ==
== checkArrays(array $expect, array $test): bool ==
This function test if every element of $expect is a memeber of the array $test. If the element of $expect is in turn an array the function is called recursivly.
This function test if every element of $expect is a memeber of the array $test. If the element of $expect is in turn an array the function is called recursivly.
== assertArrayContains(array $expect, array $test) ==
This function raises a test failure if checkArrays() with the given parameters is false otherwise a test success.

Latest revision as of 11:29, 5 October 2024


This page is incomplete

getField($loader, $fieldname = null)

A helper to access a subfield of the field $loader.

Empty $fieldname

When fieldname is empty $load is returned

Example:

$test = 10;
getField($test); // Returns 10;

$fieldname is a string

When $fieldname is a string, then a member of load with this name is returned

Example:

$test = new StdClass();
$test->member = 'ABC';
getField($test, 'member'); // Returns 'ABC';

$fieldname is a array index

When $fieldname is a string containing a array index (like field[index]) this index is returned.

Example:

$test = [1,2,3];
getField($test,'[1]'); // Returns 2

$fieldname is a double array index

When $fieldname is a string containing a double array index (like field[index][index2]) this index is returned.

Example:

$test = [[1,2,3],[4,5,6][7,8,9]];
getField($test,'[1][1]'); // Returns 5

$fieldname is a arrowed string

When $fieldname is a string containing an arrow (like field->subfield) the subfield is returned.

Example:

$test = new StdClass();
$subfield = new StdClass();
$subfield->member = 'ABC';
$test->subfield = $subfield;
getField($test, 'subfield->member'); // Returns 'ABC';

$fieldname is a value with array index

When $fieldname is a string containing an field with array index (like field[index]) this index is returned.

Example:

$test = new StdClass();
$array = [1,2,3];
$test->subfield = $array;
getField($test,'subfield[1]'); // Returns 2

$fieldname is a double array index

When $fieldname is a string containing a double array index (like field[index][index2]) this index is returned.

Example:

$test = new StdClass();
$array = [[1,2,3],[4,5,6][7,8,9]];
$test->subfield = $array;
getField($test,'subfield[1][1]'); // Returns 5

invokeMethod(object &$object, string $methodName, array $parameters = array())

This function calls the protected method $methodName of the object $object with the parameters $parameters.

Example:

callProtectedMethod(object &$object, string $methodName, array $parameters = array())

An alias to invokeMethod().

setProtectedProperty(object &$object,string $property_name,mixed $value)

This function sets the value of the protected property $property_name of the object $object to the value $value.

getProtectedProptery(object &$object,string $property_name): mixed

This method returns the protected property $property_name of the object $object.

checkArrays(array $expect, array $test): bool

This function test if every element of $expect is a memeber of the array $test. If the element of $expect is in turn an array the function is called recursivly.