The PAX tests Class is a unique approach to unit testing your class methods. Below is detailed layout of how the class works.
app > php > pages > api > test.php
require_once(DIR_APP);
$app = new app();
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'=>[
]
]
]);
Name | Type | Example | Description |
---|---|---|---|
message | String |
|
Explanation of Test |
vars | Array |
|
Variables that you want to pass into the method. |
and | Array |
|
If statement clause connected by AND |
or | Array |
|
If statement clause connected by OR |
func | Function |
|
Secondary Method to pass the original method through. |
func_vars | Array |
|
Variables to pass through the secondary method ('_val' will be the primary method's results) |
skip | Integer | 1 | Will skip the test. |
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'
]
]
]);
Variable | Example |
---|---|
$app->get("tests")->html |
|
Variable | Example |
---|---|
$app->get("tests")->cli |
|
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 |
|