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

Merged in ahoffmann_wisc/rpc-netid-php/add-ping-method (pull request #4)

Add ping method
parents c09b684c cffd4de6
No related branches found
Tags 1.4.1
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,19 @@ class RpcNetidClientSoap implements RpcNetidClient {
throw new RpcNetidClientSoapException("Unexpected status code: {$result->result}",
RpcNetidClientSoapException::UNEXPECTED_STATUS_CODE );
}
public function ping() {
$result = $this->getSoapClient()->ping([]);
if ( isset( $result->version ) ) {
return $result->version;
} else {
throw new RpcNetidClientSoapException("version not returned by web service",
RpcNetidClientSoapException::UNEXPECTED_RESPONSE);
}
}
/**
* Creates a client initialized with the given configuration otpions
......@@ -371,7 +384,7 @@ class RpcNetidClientSoap implements RpcNetidClient {
}
/**
* @return SoapClient
* @return \SoapClient
*/
public function getSoapClient() { return $this->soapClient; }
......
......@@ -662,4 +662,29 @@ class RpcNetidClientSoapTest extends PHPUnit_Framework_TestCase {
}
/**
* @test ping() returns the version on success
*/
function ping_200_returns_version() {
$result = new stdClass();
$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 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();
$this->mockSoapClient->expects($this->any())->method('ping')->will($this->returnValue($result));
$client = new RpcNetidClientSoap($this->mockSoapClient);
$client->ping();
}
}
......@@ -259,5 +259,11 @@ class RpcNetidClientSoapIT extends PHPUnit_Framework_TestCase {
$this->assertFalse( $result->getIsValid() );
$this->assertNotEmpty( $result->getReasons() );
}
/** @test */
public function ping_control() {
$result = self::$client->ping();
$this->assertNotEmpty( $result );
}
}
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