Skip to content

Commit

Permalink
updated base class,added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
redcap3000 committed Jul 25, 2011
1 parent 1bf03ac commit c99d4ad
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
4 changes: 2 additions & 2 deletions APIBaseClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public function _request($path, $method, $data=false, $headers=false) {

$url = $this->_root . $path;
curl_setopt($this->_http, CURLOPT_URL, $url);
if($headers) curl_setopt($this->_http, CURLOPT_HTTPHEADER, $headers);

if($headers) curl_setopt($this->_http, CURLOPT_HTTPHEADER, array($headers));
curl_setopt($this->_http, CURLOPT_CUSTOMREQUEST, $method);

$result = curl_exec($this->_http);
Expand Down
49 changes: 49 additions & 0 deletions TestOfRxNorm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?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('toxnetApi.php');
// the name of the api class is 'yourApi'
class TestOfApiClass extends UnitTestCase {
public $api;
// put your class name here
public static $class_name = 'toxnetApi';
function testApiConstructs(){
$this->api = new self::$class_name();
$this->check_class_params('_http _root api_url');
}

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));
}
}
}
?>

0 comments on commit c99d4ad

Please sign in to comment.