Skip to content
Snippets Groups Projects
Commit 8861ffbd authored by Andrew Hoffmann's avatar Andrew Hoffmann
Browse files

Added the ping() method to RpcNetidClientSoap

ACCTREC-299
parent 9c7dc5f1
No related branches found
No related tags found
No related merge requests found
......@@ -100,6 +100,14 @@ interface RpcNetidClient {
* @return RpcNetidStructValidationResponse validation response including reasons for failure.
*/
function checkLOA( $uid, \DateTime $birthdate, $wiscard = null );
/**
* Returns the version of the NetID web service.
*
* @return string the version of the web service
* @throws RpcNetidClientException if web service responds with status code other than 200
*/
function ping();
}
......
......@@ -338,6 +338,24 @@ class RpcNetidClientSoap implements RpcNetidClient {
throw new RpcNetidClientSoapException("Unexpected status code: {$result->result}",
RpcNetidClientSoapException::UNEXPECTED_STATUS_CODE );
}
public function ping() {
$result = $this->getSoapClient()->ping([]);
if ( $result->result === 200 ) {
if ( isset( $result->version ) ) {
return $result->version;
} else {
throw new RpcNetidClientSoapException("version not returned by web service",
RpcNetidClientSoapException::UNEXPECTED_RESPONSE);
}
}
throw new RpcNetidClientSoapException("Unexpected status code: {$result->result}",
RpcNetidClientSoapException::UNEXPECTED_STATUS_CODE );
}
/**
* Creates a client initialized with the given configuration otpions
......@@ -371,7 +389,7 @@ class RpcNetidClientSoap implements RpcNetidClient {
}
/**
* @return SoapClient
* @return \SoapClient
*/
public function getSoapClient() { return $this->soapClient; }
......
......@@ -662,4 +662,45 @@ class RpcNetidClientSoapTest extends PHPUnit_Framework_TestCase {
}
/**
* @test ping() returns the version on success
*/
function ping_200_returns_version() {
$result = new stdClass();
$result->result = 200;
$result->version = "1.0";
$this->mockSoapClient->expects($this->any())->method('ping')->will($this->returnValue($result));
$client = new RpcNetidClientSoap($this->mockSoapClient);
$this->assertEquals( "1.0", $client->ping() );
}
/**
* @test ping() throws exception if unexpected response code
* @expectedException \edu\wisc\doit\RpcNetidClientSoapException
* @expectedExceptionCode 100
*/
function ping_500_throws() {
$result = new stdClass();
$result->result = 500;
$this->mockSoapClient->expects($this->any())->method('ping')->will($this->returnValue($result));
$client = new RpcNetidClientSoap($this->mockSoapClient);
$client->ping();
}
/**
* @test throws exception if version is not supplied by web service
* @expectedException \edu\wisc\doit\RpcNetidClientSoapException
* @expectedExceptionCode 101
*/
function ping_no_version_throws() {
$result = new stdClass();
$result->result = 200;
$this->mockSoapClient->expects($this->any())->method('ping')->will($this->returnValue($result));
$client = new RpcNetidClientSoap($this->mockSoapClient);
$client->ping();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment