diff --git a/library/Class/WebService/MappedSoapClient.php b/library/Class/WebService/MappedSoapClient.php index bb9aa22fdf11c25ff3ebdc7485bb9c9c36754c72..b9fafb58f3b832b0ef84b5680196676d90e51018 100644 --- a/library/Class/WebService/MappedSoapClient.php +++ b/library/Class/WebService/MappedSoapClient.php @@ -19,36 +19,45 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +/** + * A SoapClient which automatically map existing + * PHP classes to WSDL types with the same name + */ class Class_WebService_MappedSoapClient extends SoapClient { - /* - * A SoapClient which automatically map existing - * PHP classes to WSDL types with the same name - */ - - protected function __getWSDLStructTypes(){ - $types = array(); - + protected function __getWSDLStructTypes() { + $types = []; foreach($this->__getTypes() as $type) { - preg_match("/([a-z0-9_]+)\s+([a-z0-9_]+(\[\])?)(.*)?/si", $type, $matches); - if ($matches[1] == 'struct') $types[]=$matches[2]; + preg_match('/([a-z0-9_]+)\s+([a-z0-9_]+(\[\])?)(.*)?/si', $type, $matches); + if ($matches[1] == 'struct') + $types[] = $matches[2]; } return $types; } - protected function __generateClassmap(){ - $classnames = $this->__getWSDLStructTypes(); + protected function __generateClassmap() { + $classnames = $this->__getWSDLStructTypes(); foreach($classnames as $classname) if (class_exists($classname, false)) $this->_classmap[$classname] = $classname; } + + /** + * @param $name string + * @return boolean + */ + public function hasFunction($name) { + foreach ($this->__getFunctions() as $function) + if (false !== strpos($function, ' ' . $name . '(')) + return true; + return false; + } + - public function __construct($wsdl, $options = array()) { + public function __construct($wsdl, $options=[]) { parent::__construct($wsdl, $options); $this->__generateClassmap(); } } - - ?> \ No newline at end of file diff --git a/library/Class/WebService/SIGB/Orphee/Service.php b/library/Class/WebService/SIGB/Orphee/Service.php index 080ac21100b295774c83075bf4d5d1f94d9b0398..61de872278756d1c0cf1d78913b7acc71945729b 100644 --- a/library/Class/WebService/SIGB/Orphee/Service.php +++ b/library/Class/WebService/SIGB/Orphee/Service.php @@ -26,18 +26,6 @@ class Class_WebService_SIGB_Orphee_Service extends Class_WebService_SIGB_Abstrac protected $_key; protected $_soap_options; - protected static $SOAP_CLIENT_CLASS='Class_WebService_MappedSoapClient'; - - public static function newSoapClient($wsdl, $options) { - $soap_class = self::$SOAP_CLIENT_CLASS; - return new $soap_class($wsdl, $options); - } - - - public static function setSoapClientClass($soap_class) { - self::$SOAP_CLIENT_CLASS = $soap_class; - } - public static function getService($wsdl, $key=null) { return new self($wsdl, $key, @@ -54,12 +42,12 @@ class Class_WebService_SIGB_Orphee_Service extends Class_WebService_SIGB_Abstrac $this->_wsdl = $wsdl; $this->_key = $key; $this->_soap_options = $soap_options; - $this->connect(); } public function __destruct() { - $this->disconnect(); + if ($this->isConnected()) + $this->disconnect(); } @@ -83,261 +71,236 @@ class Class_WebService_SIGB_Orphee_Service extends Class_WebService_SIGB_Abstrac return $this->_search_client; try { - $this->_search_client = self::newSoapClient($this->_wsdl, $this->_soap_options); + $this->_search_client = new Class_WebService_MappedSoapClient($this->_wsdl, + $this->_soap_options); } catch (SoapFault $e) { - $this->_guid = null; } + return $this->_search_client; } - public function connect() { + /** @category testing */ + public function setSearchClient($client) { + $this->_search_client = $client; + return $this; + } + + + public function getSessionStrategy() { + if (null === $this->_session_strategy) { + $this->_session_strategy = Class_WebService_SIGB_Orphee_SessionStrategy::newFrom($this->getSearchClient(), + $this->_key); + $this->_session_strategy->connect(); + } + return $this->_session_strategy; + } + + + public function isConnected() { try { - $this->getSearchClient(); - $this->getSessionStrategy()->connect(); - } catch (SoapFault $e) { - $this->_guid = null; + return $this->getSessionStrategy()->isConnected(); + } catch(Exception $e) { } - return $this; + return false; } - public function getSessionStrategy() { - if (null === $this->_session_strategy) - $this->_session_strategy = Class_WebService_SIGB_Orphee_SessionStrategy::newFrom($this->_search_client, $this->_key); - return $this->_session_strategy; - } - - - public function isConnected() { - return $this->getSessionStrategy()->isConnected(); - } - - - /** @codeCoverageIgnore */ - protected function _dumpSoapTrace() { - var_dump($this->_search_client->__getLastRequestHeaders()); - var_dump($this->_search_client->__getLastRequest()); - var_dump($this->_search_client->__getLastResponseHeaders()); - var_dump($this->_search_client->__getLastResponse()); - } - - - public function getEmprunteur($user) { - return $this->willTry( - function() use ($user) { - $result = ($this->hasGetAdh()) ? - $this->_search_client->GetAdh(GetAdh::withNo($user->getLogin())): - $this->_search_client->GetInfoUserCarte(GetInfoUserCarte::withNo($user->getLogin())); - - if (!$emprunteur = Class_WebService_SIGB_Orphee_GetInfoUserCarteResponseReader - ::newInstance() - ->getEmprunteurFromXML($result->getXml())) - return $this->newNullEmprunteur(); - - return $emprunteur->beValid()->setService($this); - }); - } - - - protected function hasGetAdh() { - foreach ($this->_search_client->__getFunctions() as $function) - if (false !== strpos($function, 'GetAdh(')) - return true; - return false; - } - - - public function newNullEmprunteur() { - return Class_WebService_SIGB_Emprunteur::newInstance() - ->reservationsAddAll(array()) - ->empruntsAddAll(array()); - } - - - public function getReservationsOf($emprunteur) { - return $this->willTry( - function() use ($emprunteur) { - return Class_WebService_SIGB_Orphee_GetLstRsvResponseReader::newInstance() - ->getReservationsFromXML($this->getSearchClient() - ->GetLstRsv(GetLstRsv::withAdh($emprunteur->getId())) - ->getXml()); - }); - } - - - public function getEmpruntsOf($emprunteur) { - return $this->willTry( - function () use ($emprunteur) { - return Class_WebService_SIGB_Orphee_GetLstPretResponseReader::newInstance() - ->getEmpruntsFromXML($this->getSearchClient() - ->GetLstPret(GetLstPret::withAdh($emprunteur->getId())) - ->getXml()); - }); - } - - - protected function withUserDo($user, $id, $serviceClosure, $errorClosure) { - try { - $emprunteur = $this->getEmprunteur($user); - } catch (Exception $e) { - return ['statut' => false, 'erreur' => $e->getMessage()]; - } - - try { - $result = $serviceClosure($id, $emprunteur); - } catch (SoapFault $e) { - return ['statut' => false, - 'erreur' => 'Le SIGB Orphée a retourné l\'erreur suivante: '.$e->getMessage()]; - } - - if ($message = $errorClosure($result)) - return ['statut' => false, 'erreur' => $message]; - return ['statut' => true, 'erreur' => '']; - } - - - public function reserverExemplaire($user, $exemplaire, $code_annexe) { - $notice_id = $this->removeOrpheeNoticePrefix($exemplaire->getIdOrigine()); - return $this->withUserDo( - $user, $notice_id, - function ($id, $emprunteur) { - return $this->getSearchClient() - ->RsvNtcAdh(RsvNtcAdh::withNoticeUserNo($id, $emprunteur->getId())); - }, - function ($result) { - $datas = simplexml_load_string($result->getXml()); - return ($datas->msg->code == 1) ? false : (string)$datas->msg->libelle; - }); - } - - - public function supprimerReservation($user, $notice_id) { - return $this->withUserDo( - $user, $notice_id, - function ($id, $emprunteur) { - return $this->getSearchClient() - ->DelRsv(DelRsv::withNoticeUserNo($id, $emprunteur->getId())); - }, - function ($result) { - return ($result->DelRsvResult == 1) ? false : 'La suppression a échoué'; - }); - } - - - public function prolongerPret($user, $document_id) { - return $this->withUserDo( - $user, $document_id, - function ($id, $emprunteur) { - return $this->getSearchClient() - ->ProlongePret(ProlongePret::withDocumentUser($id, $emprunteur->getId())); - }, - function ($result) { - $datas = simplexml_load_string($result->getXml()); - return ($datas->msg->code == 1) ? false : (string)$datas->msg->libelle; - }); - } + /** @codeCoverageIgnore */ + protected function _dumpSoapTrace() { + var_dump($this->_search_client->__getLastRequestHeaders()); + var_dump($this->_search_client->__getLastRequest()); + var_dump($this->_search_client->__getLastResponseHeaders()); + var_dump($this->_search_client->__getLastResponse()); + } + public function getEmprunteur($user) { + return $this->willTry( + function() use ($user) { + if (!$this->isConnected()) + return $this->newNullEmprunteur(); - public function getExemplaire($notice_id, $code_barre){ - if (!$item = Class_Exemplaire::findFirstBy(['code_barres' => $code_barre])) - return new Class_WebService_SIGB_Exemplaire(null); + $result = ($this->hasGetAdh()) ? + $this->_search_client->GetAdh(GetAdh::withNo($user->getLogin())): + $this->_search_client->GetInfoUserCarte(GetInfoUserCarte::withNo($user->getLogin())); - if (!$notice = $item->getNotice()) - return new Class_WebService_SIGB_Exemplaire(null); - - $tome = $notice->isPeriodique() ? (int)$notice->getTomeAlpha() : 0; - $id = $this->removeOrpheeNoticePrefix($notice_id); + if (!$emprunteur = Class_WebService_SIGB_Orphee_GetInfoUserCarteResponseReader + ::newInstance() + ->getEmprunteurFromXML($result->getXml())) + return $this->newNullEmprunteur(); + return $emprunteur->beValid()->setService($this); + }); + } - $result = $this->getSearchClient()->GetLstDmt(GetLstDmt::withNtcAndFas($id, $tome)); - $xml = $result->getXml(); - $notice = Class_WebService_SIGB_Orphee_GetLstDmtResponseReader::newInstance()->getNoticeFromXML($xml); - if (!isset($notice) || ($exemplaire = $notice->getExemplaireByCodeBarre($code_barre)) == null){ - $exemplaire = new Class_WebService_SIGB_Exemplaire(null); - } - return $exemplaire; + + protected function hasGetAdh() { + return $this->_search_client->hasFunction('GetAdh'); } - public function getNotice($id) { - // disabled - see getExemplaire - return new Class_WebService_SIGB_Notice($id); - } + public function newNullEmprunteur() { + return Class_WebService_SIGB_Emprunteur::newInstance() + ->reservationsAddAll([]) + ->empruntsAddAll([]); + } + + + /** @return array */ + public function getReservationsOf($emprunteur) { + return $this->willTry( + function() use ($emprunteur) { + if (!$this->isConnected()) + return []; + return Class_WebService_SIGB_Orphee_GetLstRsvResponseReader::newInstance() + ->getReservationsFromXML($this->getSearchClient() + ->GetLstRsv(GetLstRsv::withAdh($emprunteur->getId())) + ->getXml()); + }); + } + + /** @return array */ + public function getEmpruntsOf($emprunteur) { + return $this->willTry( + function () use ($emprunteur) { + if (!$this->isConnected()) + return []; + return Class_WebService_SIGB_Orphee_GetLstPretResponseReader::newInstance() + ->getEmpruntsFromXML($this->getSearchClient() + ->GetLstPret(GetLstPret::withAdh($emprunteur->getId())) + ->getXml()); + }); + } - public function removeOrpheeNoticePrefix($id) { - return str_replace('frOr', '', $id); - } + protected function withUserDo($user, $id, $serviceClosure, $errorClosure) { + try { + $emprunteur = $this->getEmprunteur($user); + } catch (Exception $e) { + return ['statut' => false, 'erreur' => $e->getMessage()]; + } - public function getGUID() { - return $this->_guid; - } + try { + $result = $serviceClosure($id, $emprunteur); + } catch (SoapFault $e) { + return ['statut' => false, + 'erreur' => 'Le SIGB Orphée a retourné l\'erreur suivante: '.$e->getMessage()]; + } + if ($message = $errorClosure($result)) + return ['statut' => false, 'erreur' => $message]; + return ['statut' => true, 'erreur' => '']; + } - public function _newOrpheeException($message) { - throw new Class_WebService_Exception('Le SIGB Orphée a retourné l\'erreur suivante: '.$message); - } - } + public function reserverExemplaire($user, $exemplaire, $code_annexe) { + $notice_id = $this->removeOrpheeNoticePrefix($exemplaire->getIdOrigine()); + return $this->withUserDo( + $user, $notice_id, + function ($id, $emprunteur) use ($code_annexe) { + if ($this->hasSetAdhDispoAnx()) + $this->getSearchClient() + ->setAdhDispoAnx(setAdhDispoAnx::with($code_annexe)); + return $this->getSearchClient() + ->RsvNtcAdh(RsvNtcAdh::withNoticeUserNo($id, $emprunteur->getId())); + }, + function ($result) { + $datas = simplexml_load_string($result->getXml()); + return ($datas->msg->code == 1) ? false : (string)$datas->msg->libelle; + }); + } + protected function hasSetAdhDispoAnx() { + return $this->_search_client->hasFunction('setAdhDispoAnx'); + } + public function supprimerReservation($user, $notice_id) { + return $this->withUserDo( + $user, $notice_id, + function ($id, $emprunteur) { + return $this->getSearchClient() + ->DelRsv(DelRsv::withNoticeUserNo($id, $emprunteur->getId())); + }, + function ($result) { + return ($result->DelRsvResult == 1) ? false : 'La suppression a échoué'; + }); + } - class Class_WebService_SIGB_Orphee_XMLFilter { - public static function filter($xml) { - $xml = trim($xml); - $xml = preg_replace('/<!\[CDATA\[+/', '', $xml); - $xml = preg_replace('/\]+>+/', '', $xml); + public function prolongerPret($user, $document_id) { + return $this->withUserDo( + $user, $document_id, + function ($id, $emprunteur) { + return $this->getSearchClient() + ->ProlongePret(ProlongePret::withDocumentUser($id, $emprunteur->getId())); + }, + function ($result) { + $datas = simplexml_load_string($result->getXml()); + return ($datas->msg->code == 1) ? false : (string)$datas->msg->libelle; + }); + } - return $xml; - if (substr($xml, 0, 9)== '<![CDATA[') - return substr($xml, 9, -3); - } - } + public function getExemplaire($notice_id, $code_barre){ + if (!$this->isConnected() + || (!$item = Class_Exemplaire::findFirstBy(['code_barres' => $code_barre])) + || (!$notice = $item->getNotice())) + return new Class_WebService_SIGB_Exemplaire(null); + $tome = $notice->isPeriodique() ? (int)$notice->getTomeAlpha() : 0; + $id = $this->removeOrpheeNoticePrefix($notice_id); + $result = $this->getSearchClient()->GetLstDmt(GetLstDmt::withNtcAndFas($id, $tome)); + $xml = $result->getXml(); + $notice = Class_WebService_SIGB_Orphee_GetLstDmtResponseReader::newInstance()->getNoticeFromXML($xml); - class GetId { - public $str; // string - public $key; // string - } + return !isset($notice) + || (null == ($exemplaire = $notice->getExemplaireByCodeBarre($code_barre))) + ? new Class_WebService_SIGB_Exemplaire(null) + : $exemplaire; + } - class GetIdResponse { - public $GetIdResult; // string + /** + * @deprecated + * @see getExemplaire + */ + public function getNotice($id) { + return new Class_WebService_SIGB_Notice($id); + } - public static function withIdResult($id) { - $instance = new self(); - $instance->GetIdResult = $id; - return $instance; - } - } + public function removeOrpheeNoticePrefix($id) { + return str_replace('frOr', '', $id); + } - class GetToken { - public $key; - public static function newWith($key) { - $instance = new self(); - $instance->key = $key; - return $instance; + public function _newOrpheeException($message) { + throw new Class_WebService_Exception('Le SIGB Orphée a retourné l\'erreur suivante: '.$message); } } -class GetTokenResponse { - public $GetTokenResult; +class Class_WebService_SIGB_Orphee_XMLFilter { + public static function filter($xml) { + $xml = trim($xml); + $xml = preg_replace('/<!\[CDATA\[+/', '', $xml); + $xml = preg_replace('/\]+>+/', '', $xml); + + return $xml; + if (substr($xml, 0, 9)== '<![CDATA[') + return substr($xml, 9, -3); + + } } class GetLstDmt { - public $ntc; // string - public $fas; // int + public $ntc; // string + public $fas; // int public static function withNtcAndFas($ntc, $fas) { $instance = new self(); @@ -348,10 +311,8 @@ class GetLstDmt { } - - class GetLstDmtResponse { - public $GetLstDmtResult; // string + public $GetLstDmtResult; // string public static function withResult($xml) { $instance = new self(); @@ -366,10 +327,8 @@ class GetLstDmtResponse { } - - class GetInfoUserCarte { - public $cb; + public $cb; public static function withNo($no) { $instance = new self(); @@ -379,8 +338,6 @@ class GetInfoUserCarte { } - - class GetInfoUserCarteResponse { public $GetInfoUserCarteResult; // String @@ -397,7 +354,6 @@ class GetInfoUserCarteResponse { } - class GetAdh { public $carte; @@ -412,7 +368,7 @@ class GetAdh { class GetAdhResponse { /** @var string */ - public $GetAdhResult; + public $GetAdhResult; public static function withResult($xml) { $instance = new self(); @@ -427,14 +383,11 @@ class GetAdhResponse { } - - class GetLstPret { - public $adh; // int - public $scrit; // string - public $nb_res; // int - public $export; // short - + public $adh; // int + public $scrit; // string + public $nb_res; // int + public $export; // short public static function withAdh($adh) { $instance = new self(); @@ -447,10 +400,8 @@ class GetLstPret { } - - class GetLstPretResponse { - public $GetLstPretResult; // string + public $GetLstPretResult; // string public static function withResult($xml) { $instance = new self(); @@ -465,11 +416,9 @@ class GetLstPretResponse { } - class GetLstRsv { - public $adh; // int - public $nb_res; // int - + public $adh; // int + public $nb_res; // int public static function withAdh($adh) { $instance = new self(); @@ -480,11 +429,8 @@ class GetLstRsv { } - - class GetLstRsvResponse { - public $GetLstRsvResult; // string - + public $GetLstRsvResult; // string public static function withResult($xml) { $instance = new self(); @@ -495,16 +441,14 @@ class GetLstRsvResponse { public function getXml() { return Class_WebService_SIGB_Orphee_XMLFilter::filter($this->GetLstRsvResult); - } + } } - - class RsvNtcAdh { - public $ntc; // string - public $fas; // int - public $adh; // int + public $ntc; // string + public $fas; // int + public $adh; // int public static function withNoticeUserNo($ntc, $adh) { $instance = new self(); @@ -516,11 +460,8 @@ class RsvNtcAdh { } - - class RsvNtcAdhResponse { - public $RsvNtcAdhResult; // string - + public $RsvNtcAdhResult; // string public static function withResult($xml) { $instance = new self(); @@ -528,18 +469,17 @@ class RsvNtcAdhResponse { return $instance; } + public function getXml() { return Class_WebService_SIGB_Orphee_XMLFilter::filter($this->RsvNtcAdhResult); } } - - class DelRsv { - public $adh; // int - public $ntc; // int - public $fas; // int + public $adh; // int + public $ntc; // int + public $fas; // int public static function withNoticeUserNo($ntc, $adh) { $instance = new self(); @@ -551,10 +491,8 @@ class DelRsv { } - - class DelRsvResponse { - public $DelRsvResult; // short + public $DelRsvResult; // short public static function withResult($result) { $instance = new self(); @@ -564,11 +502,9 @@ class DelRsvResponse { } - - class ProlongePret { - public $adh; // int - public $dmt; // string + public $adh; // int + public $dmt; // string public static function withDocumentUser($dmt, $adh) { $instance = new self(); @@ -580,10 +516,8 @@ class ProlongePret { - class ProlongePretResponse { - public $ProlongePretResult; // string - + public $ProlongePretResult; // string public static function withResult($result) { $instance = new self(); @@ -597,14 +531,15 @@ class ProlongePretResponse { } +class setAdhDispoAnx { + /** @var string */ + public $anx; - -class EndSession { -} - -class EndSessionResponse { + public static function with($code) { + $instance = new self(); + $instance->anx = $code; + return $instance; + } } - - ?> \ No newline at end of file diff --git a/library/Class/WebService/SIGB/Orphee/SessionStrategy.php b/library/Class/WebService/SIGB/Orphee/SessionStrategy.php index 8dfba8cf1c18d90202c5c9b243ce8076c055ed14..4d3f67aeb77afc3b34548883166cf36361932dc1 100644 --- a/library/Class/WebService/SIGB/Orphee/SessionStrategy.php +++ b/library/Class/WebService/SIGB/Orphee/SessionStrategy.php @@ -25,10 +25,8 @@ class Class_WebService_SIGB_Orphee_SessionStrategy { protected $_session_id; public static function newFrom($soapClient, $key) { - $strategies = ['GetToken', 'GetId']; - - foreach($strategies as $strategy) - if (self::hasFunction($strategy, $soapClient)) { + foreach(['GetToken', 'GetId'] as $strategy) + if ($soapClient->hasFunction($strategy)) { $class_name = 'Class_WebService_SIGB_Orphee_SessionStrategy' . $strategy; return new $class_name($soapClient, $key); } @@ -37,14 +35,6 @@ class Class_WebService_SIGB_Orphee_SessionStrategy { } - protected static function hasFunction($name, $soapClient) { - foreach ($soapClient->__getFunctions() as $function) - if (false !== strpos($function, ' ' . $name . '(')) - return true; - return false; - } - - public function __construct($client, $key) { $this->_client = $client; $this->_key = $key; @@ -52,6 +42,9 @@ class Class_WebService_SIGB_Orphee_SessionStrategy { public function connect() { + if ($this->isConnected()) + return $this; + $this->setSessionId(); $this->_client->__setCookie('ASP.NET_SessionId', $this->_session_id); return $this; @@ -102,4 +95,42 @@ class Class_WebService_SIGB_Orphee_SessionStrategyGetToken extends Class_WebServ class Class_WebService_SIGB_Orphee_SessionStrategyNull extends Class_WebService_SIGB_Orphee_SessionStrategy{} + +class GetId { + public $str; // string + public $key; // string +} + + +class GetIdResponse { + public $GetIdResult; // string + + public static function withIdResult($id) { + $instance = new self(); + $instance->GetIdResult = $id; + return $instance; + } +} + + +class GetToken { + public $key; + + public static function newWith($key) { + $instance = new self(); + $instance->key = $key; + return $instance; + } +} + +class GetTokenResponse { + public $GetTokenResult; +} + +class EndSession { +} + +class EndSessionResponse { +} + ?> \ No newline at end of file diff --git a/tests/library/Class/WebService/SIGB/OrpheeServiceTest.php b/tests/library/Class/WebService/SIGB/OrpheeServiceTest.php index 7d4a6909433453134627b0919ec3d45060a376ef..dfaafae314e3c1ddce57c244ecf013667d301055 100644 --- a/tests/library/Class/WebService/SIGB/OrpheeServiceTest.php +++ b/tests/library/Class/WebService/SIGB/OrpheeServiceTest.php @@ -20,39 +20,15 @@ */ include_once('Class/WebService/SIGB/Orphee/Service.php'); -include_once('OrpheeFixtures.php'); - -class MapppedSoapClientForTesting extends Class_WebService_MappedSoapClient { - public $wsdl; - public $options; - - public function __construct($wsdl, $options) { - $this->wsdl = $wsdl; - $this->options = $options; - } - - - public function getId() { - return GetIdResponse::withIdResult('clong'); - } - - - public function __getFunctions() { - return []; - } - - - public function EndSession() { - } -} +include_once('Class/WebService/SIGB/Orphee/SessionStrategy.php'); +include_once('OrpheeFixtures.php'); class Class_WebService_SIGB_Orphee_ServiceForTesting extends Class_WebService_SIGB_Orphee_Service { public function __construct($search_client) { $this->_search_client = $search_client; } - public function getSearchClient() { $result = $this->_search_client->GetId(new GetId()); $this->_guid = $result->GetIdResult; @@ -69,26 +45,28 @@ class OrpheeServiceGetServiceTest extends Storm_Test_ModelTestCase { public function setUp() { parent::setUp(); - Class_WebService_SIGB_Orphee_Service::setSoapClientClass('MapppedSoapClientForTesting'); - $this->_orphee = Class_WebService_SIGB_Orphee_Service::getService('tests/fixtures/orphee.wsdl'); - } - + $this->_search_client = Storm_Test_ObjectWrapper::mock() + ->whenCalled('hasFunction')->answers(false) + ->whenCalled('hasFunction')->with('GetId')->answers(true) + ->whenCalled('GetId')->answers(GetIdResponse::withIdResult('1234')) + ->whenCalled('__setCookie')->answers(true) + ->whenCalled('EndSession')->answers(true); - /** @test */ - public function searchClientShouldBeAnInstanceOfMappedSoapClient() { - $this->assertInstanceOf('Class_WebService_MappedSoapClient', $this->_orphee->getSearchClient()); + $this->_orphee = Class_WebService_SIGB_Orphee_Service::getService('tests/fixtures/orphee.wsdl'); + $this->_orphee->setSearchClient($this->_search_client); + $this->_orphee->isConnected(); } /** @test */ - public function clientWSDLShouldBeOrpheeWSDL() { - $this->assertEquals('tests/fixtures/orphee.wsdl', $this->_orphee->getSearchClient()->wsdl); + public function shouldCallEndSessionOnServiceDestruction() { + unset($this->_orphee); + gc_collect_cycles(); + $this->assertTrue($this->_search_client->methodHasBeenCalled('EndSession')); } } - - abstract class OrpheeServiceTestCase extends Storm_Test_ModelTestCase { protected $_search_client; protected $_orphee; @@ -96,9 +74,11 @@ abstract class OrpheeServiceTestCase extends Storm_Test_ModelTestCase { public function setUp(){ parent::setUp(); - $this->_search_client = Storm_Test_ObjectWrapper::on(new Class_WebService_MappedSoapClient('tests/fixtures/orphee.wsdl')); - + $this->_search_client = Storm_Test_ObjectWrapper::mock(); $this->_search_client + ->whenCalled('hasFunction') + ->answers(false) + ->whenCalled('__setCookie') ->answers(null) @@ -107,15 +87,16 @@ abstract class OrpheeServiceTestCase extends Storm_Test_ModelTestCase { $this->_beforeOrpheeServiceCreate(); $this->_orphee = new Class_WebService_SIGB_Orphee_ServiceForTesting($this->_search_client); - $this->_orphee->connect(); $this->_henry_dupont = Class_Users::getLoader() - ->newInstanceWithId(2) - ->setLogin('10900000753'); + ->newInstanceWithId(2) + ->setLogin('10900000753'); } public function _beforeOrpheeServiceCreate(){ $this->_search_client + ->whenCalled('hasFunction')->with('GetId')->answers(true) + ->whenCalled('GetId') ->with(new GetId()) ->answers(GetIdResponse::withIdResult('1234')); @@ -123,19 +104,21 @@ abstract class OrpheeServiceTestCase extends Storm_Test_ModelTestCase { } - - class OrpheeServiceBorrowerSoapActionDetectionTest extends OrpheeServiceTestCase { - /** @test */ - public function withoutGetAdhShouldCallGetInfoUserCarte() { + public function setUp() { + parent::setUp(); $this->_search_client - ->whenCalled('__getFunctions') - ->answers([]) - ->whenCalled('GetInfoUserCarte') ->answers(Storm_Test_ObjectWrapper::mock() ->whenCalled('getXml') ->answers('')); + } + + + /** @test */ + public function withoutGetAdhShouldCallGetInfoUserCarte() { + $this->_search_client + ->whenCalled('hasFunction')->with('GetAdh')->answers(false); $this->_orphee->getEmprunteur($this->_henry_dupont); $this->assertTrue($this->_search_client->methodHasBeenCalled('GetInfoUserCarte')); @@ -145,13 +128,10 @@ class OrpheeServiceBorrowerSoapActionDetectionTest extends OrpheeServiceTestCase /** @test */ public function withGetAdhShouldCallIt() { $this->_search_client - ->whenCalled('__getFunctions') - ->answers(['GetAdhResponse GetAdh(GetAdh $parameters)']) + ->whenCalled('hasFunction')->with('GetAdh')->answers(true) ->whenCalled('GetAdh') - ->answers(Storm_Test_ObjectWrapper::mock() - ->whenCalled('getXml') - ->answers('')); + ->answers(Storm_Test_ObjectWrapper::mock()->whenCalled('getXml')->answers('')); $this->_orphee->getEmprunteur($this->_henry_dupont); $this->assertTrue($this->_search_client->methodHasBeenCalled('GetAdh')); @@ -159,34 +139,30 @@ class OrpheeServiceBorrowerSoapActionDetectionTest extends OrpheeServiceTestCase } - - class OrpheeServiceTestAutoConnectSuccessful extends OrpheeServiceTestCase { - protected $_search_client; - protected $_orphee; - - /** @test */ - public function withSuccessfulGitIdIsConnectedShouldReturnTrue(){ - $this->assertTrue($this->_orphee->isConnected()); + public function setUp() { + parent::setUp(); + $this->_search_client + ->whenCalled('hasFunction')->with('GetId')->answers(true); + $this->_orphee->isConnected(); // should connect on demand } /** @test */ - public function getGUIDShouldReturns1234() { - $this->assertEquals('1234', $this->_orphee->getGUID()); + public function withSuccessfulGetIdIsConnectedShouldReturnTrue(){ + $this->assertTrue($this->_orphee->isConnected()); } /** @test */ public function cookieShouldHaveBeenSetTo1234() { - $this->assertTrue($this->_search_client->methodHasBeenCalledWithParams('__setCookie', - array('ASP.NET_SessionId', '1234'))); + $this->assertTrue($this->_search_client + ->methodHasBeenCalledWithParams('__setCookie', + ['ASP.NET_SessionId', '1234'])); } } - - class OrpheeServiceTestAutoConnectError extends OrpheeServiceTestCase { protected $_search_client; protected $_orphee; @@ -198,49 +174,23 @@ class OrpheeServiceTestAutoConnectError extends OrpheeServiceTestCase { } - public function tearDown() { - unset($this->_orphee); - unset($this->_henry_dupont); - gc_collect_cycles(); - $this->assertFalse($this->_search_client->methodHasBeenCalled('EndSession')); - parent::tearDown(); - } - - /** @test */ public function isConnectedShouldReturnsFalse() { $this->assertFalse($this->_orphee->isConnected()); } - /** @test */ - public function guidShouldBeEmpty() { - $this->assertEmpty($this->_orphee->getGUID()); - } - - /** @test */ public function isConnectedShouldBeFalseOnSoapException() { $this->_search_client ->whenCalled('GetId') ->willDo(function(){throw new SoapFault('error', 'error');}); - $this->_orphee->connect(); $this->assertFalse($this->_orphee->isConnected()); } } - - class OrpheeServiceTestGetLstDmntWithMillenium extends OrpheeServiceTestCase { - public function _beforeOrpheeServiceCreate(){ - $this->_search_client - ->whenCalled('GetId') - ->with(new GetId()) - ->answers(GetIdResponse::withIdResult('azerty')); - } - - public function setUp() { parent::setUp(); @@ -268,21 +218,6 @@ class OrpheeServiceTestGetLstDmntWithMillenium extends OrpheeServiceTestCase { } - public function tearDown() { - unset($this->_orphee); - gc_collect_cycles(); - $this->assertTrue($this->_search_client->methodHasBeenCalled('EndSession')); - parent::tearDown(); - } - - - /** @test */ - public function cookieShouldHaveBeenSetToAzerty() { - $this->assertTrue($this->_search_client->methodHasBeenCalledWithParams('__setCookie', - array('ASP.NET_SessionId', 'azerty'))); - } - - /** @test */ public function exemplaireByCodeBarre00106001488142ShouldNotBeEmpty() { $exemplaire = $this->_orphee->getExemplaire('frOr1301700727', '00106001488142'); @@ -373,8 +308,6 @@ class OrpheeServiceTestGetLstDmntWithMillenium extends OrpheeServiceTestCase { } - - class OrpheeServiceTestGetLstDmntWithLivreEspagnol extends OrpheeServiceTestCase { public function setUp() { parent::setUp(); @@ -405,8 +338,6 @@ class OrpheeServiceTestGetLstDmntWithLivreEspagnol extends OrpheeServiceTestCase } - - class OrpheeServiceTestGetLstDmntLAmourDansLeSangReserve extends OrpheeServiceTestCase { public function setUp() { parent::setUp(); @@ -436,8 +367,6 @@ class OrpheeServiceTestGetLstDmntLAmourDansLeSangReserve extends OrpheeServiceTe } - - class OrpheeServiceTestGetLstDmntPhosphoreNo5632 extends OrpheeServiceTestCase { public function setUp() { parent::setUp(); @@ -473,8 +402,6 @@ class OrpheeServiceTestGetLstDmntPhosphoreNo5632 extends OrpheeServiceTestCase { } - - class OrpheeServiceTestGetLstDmntVagabondEnArchivage extends OrpheeServiceTestCase { public function setUp() { parent::setUp(); @@ -504,8 +431,6 @@ class OrpheeServiceTestGetLstDmntVagabondEnArchivage extends OrpheeServiceTestCa } - - class OrpheeServiceTestGetLstDmntMetamausEnCatalogage extends OrpheeServiceTestCase { public function setUp() { parent::setUp(); @@ -534,8 +459,6 @@ class OrpheeServiceTestGetLstDmntMetamausEnCatalogage extends OrpheeServiceTestC } - - class OrpheeServiceTestGetLstDmntErrorsTest extends OrpheeServiceTestCase { /** @test */ public function onInexistingExemplaireShouldReturnEmptyExemplaire() { @@ -558,8 +481,6 @@ class OrpheeServiceTestGetLstDmntErrorsTest extends OrpheeServiceTestCase { } - - class OrpheeServiceGetLstDmtResponseTest extends PHPUnit_Framework_TestCase { /** @test */ public function withStandardXmlShouldGetXMLShouldRetunsIt() { @@ -585,8 +506,6 @@ class OrpheeServiceGetLstDmtResponseTest extends PHPUnit_Framework_TestCase { } - - class OrpheeServiceGetInfoUserCarteHenryDupontWithErrorTest extends OrpheeServiceTestCase { public function setUp() { parent::setUp(); @@ -633,8 +552,6 @@ class OrpheeServiceGetInfoUserCarteHenryDupontWithErrorTest extends OrpheeServic } - - class OrpheeServiceGetInfoUserCarteHenryDupontActionErrorTest extends OrpheeServiceTestCase { public function setUp() { parent::setUp(); @@ -676,8 +593,6 @@ class OrpheeServiceGetInfoUserCarteHenryDupontActionErrorTest extends OrpheeServ } - - class OrpheeServiceGetInfoUserCarteHenryDupontWithNoXMLTest extends OrpheeServiceTestCase { public function setUp() { parent::setUp(); @@ -707,8 +622,6 @@ class OrpheeServiceGetInfoUserCarteHenryDupontWithNoXMLTest extends OrpheeServic } - - class OrpheeServiceGetInfoUserCarteHenryDupontTest extends OrpheeServiceTestCase { public function setUp() { parent::setUp(); @@ -1048,8 +961,6 @@ class OrpheeServiceGetInfoUserCarteHenryDupontTest extends OrpheeServiceTestCase } - - class OrpheeServiceReservationTest extends OrpheeServiceTestCase { /** @test */ public function testReservationSuccessful() { @@ -1062,14 +973,13 @@ class OrpheeServiceReservationTest extends OrpheeServiceTestCase { ->with(RsvNtcAdh::withNoticeUserNo('1301700727', 100753)) ->answers(RsvNtcAdhResponse::withResult('<datas><msg><code><![CDATA[1]]></code><libelle><![CDATA[Réservation mise en attente]]></libelle></msg></datas>')); - $this->assertEquals(array('statut' => true, 'erreur' => ''), - $this->_orphee->reserverExemplaire($this->_henry_dupont, - - Class_Exemplaire::getLoader() - ->newInstanceWithId(234) - ->setIdOrigine('frOr1301700727'), - - '')); + $result = $this->_orphee + ->reserverExemplaire($this->_henry_dupont, + $this->fixture('Class_Exemplaire', + ['id' => 234, + 'id_origine' => 'frOr1301700727']), + ''); + $this->assertEquals(['statut' => true, 'erreur' => ''], $result); } @@ -1090,7 +1000,32 @@ class OrpheeServiceReservationTest extends OrpheeServiceTestCase { ->newInstanceWithId(234) ->setIdOrigine('frOr401700727'), '')); - } + } + + + /** @test */ + public function reservationWithSupportedAnxChoiceShouldCallSetAdhDispoAnx() { + $this->_search_client + ->whenCalled('hasFunction')->with('setAdhDispoAnx')->answers(true) + ->whenCalled('setAdhDispoAnx')->answers(null) + + ->whenCalled('GetInfoUserCarte') + ->with(GetInfoUserCarte::withNo('10900000753')) + ->answers(GetInfoUserCarteResponse::withResult(OrpheeFixtures::xmlGetInfoUserCarteHenryDupont())) + + ->whenCalled('RsvNtcAdh') + ->with(RsvNtcAdh::withNoticeUserNo('1301700727', 100753)) + ->answers(RsvNtcAdhResponse::withResult('<datas><msg><code><![CDATA[1]]></code><libelle><![CDATA[Réservation mise en attente]]></libelle></msg></datas>')); + + $result = $this->_orphee + ->reserverExemplaire($this->_henry_dupont, + $this->fixture('Class_Exemplaire', + ['id' => 234, + 'id_origine' => 'frOr1301700727']), + 'Testing Anx'); + + $this->assertEquals(['statut' => true, 'erreur' => ''], $result); + } } @@ -1129,8 +1064,6 @@ class OrpheeServiceSupprimerReservationTest extends OrpheeServiceTestCase { } - - class OrpheeServiceProlongetPretTest extends OrpheeServiceTestCase { /** @test */ public function testProlongationEffectuee() {