From 07851c0e393cbfad976b1373ae602ef3be1cdf37 Mon Sep 17 00:00:00 2001
From: Andrew Hoffmann <andrew.hoffmann@wisc.edu>
Date: Mon, 11 May 2015 15:08:09 -0500
Subject: [PATCH] When receiving 4xx responses from checkLOA, the client will
 return a RpcNetidStructValidationResponse with valid = false instead of
 throwing an exception. 4xx are not considered "unexpected states". We need to
 be consistent on the return type at some point.  (405 returns an integere,
 all the rest return a string).

---
 .gitignore                                    |  1 +
 src/main/edu/wisc/doit/RpcNetidClientSoap.php | 16 +++----
 src/test/RpcNetidClientSoapTest.php           | 42 +++++++++----------
 3 files changed, 30 insertions(+), 29 deletions(-)

diff --git a/.gitignore b/.gitignore
index f12ca75..dd1e8f5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,7 @@
 /.project
 /.settings
 /.vagrant
+/.idea
 /composer.lock
 /vendor
 /composer.phar
diff --git a/src/main/edu/wisc/doit/RpcNetidClientSoap.php b/src/main/edu/wisc/doit/RpcNetidClientSoap.php
index 81a8c1a..7f72644 100644
--- a/src/main/edu/wisc/doit/RpcNetidClientSoap.php
+++ b/src/main/edu/wisc/doit/RpcNetidClientSoap.php
@@ -131,20 +131,20 @@ class RpcNetidClientSoap implements RpcNetidClient {
 				return new RpcNetidStructValidationResponse(false, array());
 				break;
 			case 401:
-				throw new RpcNetidClientSoapException("Web service returned 401: invalid input parameters", 
-					RpcNetidClientSoapException::UNEXPECTED_STATUS_CODE );
+				return new RpcNetidStructValidationResponse( false, array("Web service returned 401: invalid input
+				parameters"));
 				break;
 			case 402:
-				throw new RpcNetidClientSoapException("Web service returned 402: no PVI found for uid",
-					RpcNetidClientSoapException::UNEXPECTED_STATUS_CODE );
+				return new RpcNetidStructValidationResponse( false, array("Web service returned 402: no PVI found for
+				 uid") );
 				break;
 			case 403:
-				throw new RpcNetidClientSoapException("Web service returned 403: no LOA found for uid",
-					RpcNetidClientSoapException::UNEXPECTED_STATUS_CODE );
+				return new RpcNetidStructValidationResponse( false, array("Web service returned 403: no LOA found for
+				 uid") );
 				break;
 			case 404:
-				throw new RpcNetidClientSoapException("Web service returned 404: no Wiscard eligibility data found for uid",
-					RpcNetidClientSoapException::UNEXPECTED_STATUS_CODE );
+				return new RpcNetidStructValidationResponse( false, array("Web service returned 404: no Wiscard
+				eligibility data found for uid"));
 				break;
 			case 405:
 				return new RpcNetidStructValidationResponse(false, array(RpcNetidStructValidationResponse::REASON_NEEDS_WISCARD ) );
diff --git a/src/test/RpcNetidClientSoapTest.php b/src/test/RpcNetidClientSoapTest.php
index 04bb59d..06e6761 100644
--- a/src/test/RpcNetidClientSoapTest.php
+++ b/src/test/RpcNetidClientSoapTest.php
@@ -564,66 +564,66 @@ class RpcNetidClientSoapTest extends PHPUnit_Framework_TestCase {
 	}
 	
 	/**
-	 * @test throws exception if web service returns 401 (invalid parameters)
-	 * @expectedException edu\wisc\doit\RpcNetidClientSoapException
-	 * @expectedExceptionCode 100
+	 * @test returns false if web service returns 401 (invalid parameters)
 	 */
-	function checkLOA_401_throws() {
+	function checkLOA_401_returns_false() {
 	
 		$result = new stdClass();
 		$result->result = 401;
 	
 		$this->mockSoapClient->expects($this->any())->method('checkLOA')->will($this->returnValue($result));
 		$client = new RpcNetidClientSoap($this->mockSoapClient);
-		$client->checkLOA( "jsmith", new \DateTime(), 12345678901 );
+		$returned = $client->checkLOA( "jsmith", new \DateTime(), 12345678901 );
+		$this->assertInstanceOf('edu\wisc\doit\RpcNetidStructValidationResponse', $returned );
+		$this->assertFalse( $returned->getIsValid() );
 	
 	}
 	
 	/**
-	 * @test throws exception if web service returns 402 (No PVI found for UID)
-	 * @expectedException edu\wisc\doit\RpcNetidClientSoapException
-	 * @expectedExceptionCode 100
+	 * @test returns false if web service returns 402 (No PVI found for UID)
 	 */
-	function checkLOA_402_throws() {
+	function checkLOA_402_returns_false() {
 	
 		$result = new stdClass();
 		$result->result = 402;
 	
 		$this->mockSoapClient->expects($this->any())->method('checkLOA')->will($this->returnValue($result));
 		$client = new RpcNetidClientSoap($this->mockSoapClient);
-		$client->checkLOA( "jsmith", new \DateTime(), 12345678901 );
-	
+		$returned = $client->checkLOA( "jsmith", new \DateTime(), 12345678901 );
+		$this->assertInstanceOf('edu\wisc\doit\RpcNetidStructValidationResponse', $returned );
+		$this->assertFalse( $returned->getIsValid() );
+
 	}
 	
 	/**
-	 * @test throws exception if web service returns 403 (No LOA found for UID)
-	 * @expectedException edu\wisc\doit\RpcNetidClientSoapException
-	 * @expectedExceptionCode 100
+	 * @test returns false if web service returns 403 (No LOA found for UID)
 	 */
-	function checkLOA_403_throws() {
+	function checkLOA_403_returns_false() {
 	
 		$result = new stdClass();
 		$result->result = 403;
 	
 		$this->mockSoapClient->expects($this->any())->method('checkLOA')->will($this->returnValue($result));
 		$client = new RpcNetidClientSoap($this->mockSoapClient);
-		$client->checkLOA( "jsmith", new \DateTime(), 12345678901 );
+		$returned = $client->checkLOA( "jsmith", new \DateTime(), 12345678901 );
+		$this->assertInstanceOf('edu\wisc\doit\RpcNetidStructValidationResponse', $returned );
+		$this->assertFalse( $returned->getIsValid() );
 	
 	}
 	
 	/**
-	 * @test throws exception if web service returns 404 (No Wiscard eligibility found for user)
-	 * @expectedException edu\wisc\doit\RpcNetidClientSoapException
-	 * @expectedExceptionCode 100
+	 * @test returns false if web service returns 404 (No Wiscard eligibility found for user)
 	 */
-	function checkLOA_404_throws() {
+	function checkLOA_404_returns_false() {
 	
 		$result = new stdClass();
 		$result->result = 404;
 	
 		$this->mockSoapClient->expects($this->any())->method('checkLOA')->will($this->returnValue($result));
 		$client = new RpcNetidClientSoap($this->mockSoapClient);
-		$client->checkLOA( "jsmith", new \DateTime(), 12345678901 );
+		$returned = $client->checkLOA( "jsmith", new \DateTime(), 12345678901 );
+		$this->assertInstanceOf('edu\wisc\doit\RpcNetidStructValidationResponse', $returned );
+		$this->assertFalse( $returned->getIsValid() );
 	
 	}
 	
-- 
GitLab