diff --git a/src/main/edu/wisc/doit/RpcNetidClient.php b/src/main/edu/wisc/doit/RpcNetidClient.php index db9eb30b37b0409cc7d94a709076a48c207a3e05..5d99fdcbc84be4fc6f39858b959adc1f8fba80f3 100644 --- a/src/main/edu/wisc/doit/RpcNetidClient.php +++ b/src/main/edu/wisc/doit/RpcNetidClient.php @@ -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(); } diff --git a/src/main/edu/wisc/doit/RpcNetidClientSoap.php b/src/main/edu/wisc/doit/RpcNetidClientSoap.php index c522dec4d00e14669818f90eee0e1654ae5520ae..85422d85ad4208e9e31b01eee28a8cd7f0fdae4a 100644 --- a/src/main/edu/wisc/doit/RpcNetidClientSoap.php +++ b/src/main/edu/wisc/doit/RpcNetidClientSoap.php @@ -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; } diff --git a/src/test/RpcNetidClientSoapTest.php b/src/test/RpcNetidClientSoapTest.php index 3f3d956b0ef6b8a838fdea4a82b110af77c381ff..060ef838306ce375eb9a32b90e0dfd75c8a13110 100644 --- a/src/test/RpcNetidClientSoapTest.php +++ b/src/test/RpcNetidClientSoapTest.php @@ -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(); + } + }