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..0556dde78de69f800ae5306d154b1ae77ebda629 100644 --- a/src/main/edu/wisc/doit/RpcNetidClientSoap.php +++ b/src/main/edu/wisc/doit/RpcNetidClientSoap.php @@ -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; } diff --git a/src/test/RpcNetidClientSoapTest.php b/src/test/RpcNetidClientSoapTest.php index 3f3d956b0ef6b8a838fdea4a82b110af77c381ff..45332f013baf7b501be03d63d4822a93d6711ad9 100644 --- a/src/test/RpcNetidClientSoapTest.php +++ b/src/test/RpcNetidClientSoapTest.php @@ -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(); + } + } diff --git a/src/test/integration-tests/RpcNetidClientSoapIT.php b/src/test/integration-tests/RpcNetidClientSoapIT.php index b85a8856aad3c80f1b3c6215347836dcdafb9030..1870d443f1f7a71c1f647c62b21bd9c5bee0a9d9 100644 --- a/src/test/integration-tests/RpcNetidClientSoapIT.php +++ b/src/test/integration-tests/RpcNetidClientSoapIT.php @@ -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 ); + } }