-
Notifications
You must be signed in to change notification settings - Fork 3
/
TestOfOpen311Api.php
56 lines (48 loc) · 1.91 KB
/
TestOfOpen311Api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/* load simpletest library
downloadable using
wget http://downloads.sourceforge.net/project/simpletest/simpletest/simpletest_1.1/simpletest_1.1alpha3.tar.gz;
tar -zxf simpletest_1.1alpha3.tar.gz;
*/
require_once('simpletest/autorun.php');
// load baseclass
require_once('APIBaseClass.php');
// load your class here...
require_once('open311Api.php');
// the name of the api class is 'yourApi'
class TestOfApiClass extends UnitTestCase {
public $api;
// put your class name here
public static $class_name = 'open311Api';
function testApiConstructs(){
$this->api = new self::$class_name();
$this->check_class_params('_http _root api_url');
// could create something to dynamically test each method ?
$this->assertIsA($this->api->get_service_list(),'string');
$this->assertNotNull($this->api->get_service_list());
$this->assertNotNull($this->api->get_service_requests());
$this->assertIsA($this->api->get_service_requests(),'string');
}
function check_class_params($params=NULL,$mode=TRUE){
// look up parameters inside of class and see if they are set/ true
// also allow to only check for certain parameters by passing in an array with the names of those variables or a space seperated string
// parameters to look for in the object
$api_class_vars = get_class_vars(get_class($this->api));
if($params != null && is_string($params)){
$params = explode(' ',$params);
foreach($params as $key_name)
$api_vars [$key_name] = "$key_name";
$api_vars = array_intersect_key($api_class_vars,$api_vars);
}
else
$api_vars = $api_class_vars;
// anything that isnt intersected should return false
foreach($api_vars as $key=>$value){
if($mode == TRUE)
$this->assertTrue(array_key_exists($key,$api_class_vars));
elseif($mode == FALSE)
$this->assertFalse(array_key_exists($key,$api_class_vars));
}
}
}
?>