Unit Testing

The PAX tests Class is a unique approach to unit testing your class methods. Below is detailed layout of how the class works.

Load Unit Test

app > php > pages > api > test.php


    require_once(DIR_APP);
    $app = new app();

    

run($data:array);

The run method receives an associative array structure of the classes->methods that you want to run tests on. To select which classes and methods use the layout below:


$app->get("tests")->run([
    'class_name'=>[
        'method_name'=>[
            
        ],
        'second_method_name'=>[

        ]
    ]
]);
    
Method Options
Name Type Example Description
message String
"Result must be greater than 5"
Explanation of Test
vars Array
['users',22]
Variables that you want to pass into the method.
and Array

['and'=>[
    ['==',3]
]]
If statement clause connected by AND
or Array

['or'=>[
    ['>',3],
    ['<',10]
]]
If statement clause connected by OR
func Function
'array_key_exists'
Secondary Method to pass the original method through.
func_vars Array
['key','_val']
Variables to pass through the secondary method ('_val' will be the primary method's results)
skip Integer 1 Will skip the test.

Example


require_once(DIR_APP);
$app = new app(['crud']);
$app->load(['tests'],['crud']);

$app->get("tests")->run([
    'crud'=>[
        'save'=>[
            'or'=>[['==',1],['==',0]],
            'message'=>'Must return 1 or 0'
        ],
        'update'=>[
            'or'=>[['==',1],['==',0]],
            'message'=>'Must return 1 or 0'
        ],
        'delete'=>[
            'or'=>[['==',1],['==',0]],
            'message'=>'Must return 1 or 0'
        ],
        'count'=>[
            'or'=>[['==',1],['==',0]],
            'message'=>'Must return 1 or 0'
        ],
        'get'=>[
            'func'=>'is_array',
            'func_vars'=>['_val'],
            'message'=>'Must return an array'
        ],
        'search'=>[
            'func'=>'array_key_exists',
            'func_vars'=>['hits','_val'],
            'message'=>'hits key must exist'
        ]
    ]
]);
            

Results

HTML

Variable Example
$app->get("tests")->html
echo $app->get("tests")->html;



Command Line

Variable Example
$app->get("tests")->cli
echo $app->get("tests")->cli;



FAIL

You create actions depending on the success or failure fo the test. Below is an example of giving a boolean result for command line use.

Variable Example
$app->get("tests")->fail
echo $app->get("tests")->cli;
if($app->get("tests")->fail){
	exit(1);
} else {
	exit(0);
}