From ae6d5768eadcca85a791be93b882599da092a128 Mon Sep 17 00:00:00 2001
From: llaffont <llaffont@git-test.afi-sa.fr>
Date: Wed, 27 Mar 2013 14:57:27 +0000
Subject: [PATCH] =?UTF-8?q?L'opac=20peut=20fonctionner=20avec=20plusieurs?=
 =?UTF-8?q?=20webservices=20Koha=20en=20parall=C3=A8le?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 library/Class/WebService/SIGB/Koha.php | 21 +++++++++++++--------
 tests/library/Class/CommSigbTest.php   | 12 ++++++++----
 2 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/library/Class/WebService/SIGB/Koha.php b/library/Class/WebService/SIGB/Koha.php
index dec5514605a..2486b7148c9 100644
--- a/library/Class/WebService/SIGB/Koha.php
+++ b/library/Class/WebService/SIGB/Koha.php
@@ -20,26 +20,31 @@
  */
 
 class Class_WebService_SIGB_Koha {
-	protected static $service;
+	protected static $services = [];
+
+	public static function makeKey($params) {
+		return md5(serialize($params));
+	}
 
 	public static function getService($params){
-		if (!isset(self::$service)) {
-			$instance = new self();
+		$key = static::makeKey($params);
+		if (!isset(static::$services[$key])) {
+			$instance = new static();
 			$params = array_merge(['Interdire_reservation_doc_dispo' => 0],$params);
-			self::$service = Class_WebService_SIGB_Koha_Service::getService($params['url_serveur'],$params['Interdire_reservation_doc_dispo']==='1');
+			static::$services[$key] = Class_WebService_SIGB_Koha_Service::getService($params['url_serveur'],$params['Interdire_reservation_doc_dispo']==='1');
 		}
 
-		return self::$service;
+		return static::$services[$key];
 	}
 
 
-	public static function setService($service) {
-		self::$service = $service;
+	public static function setService($params, $service) {
+		static::$services[static::makeKey($params)] = $service;
 	}
 
 
 	public static function reset() {
-		self::$service = null;
+		static::$services = [];
 	}
 
 }
diff --git a/tests/library/Class/CommSigbTest.php b/tests/library/Class/CommSigbTest.php
index e44ac219b62..6f57b288a59 100644
--- a/tests/library/Class/CommSigbTest.php
+++ b/tests/library/Class/CommSigbTest.php
@@ -193,7 +193,7 @@ abstract class CommSigbTestCase extends Storm_Test_ModelTestCase {
 						 'ABC')
 			->will($this->returnValue(array('statut' => 1,
 																			'erreur' => '')));
-
+		xdebug_break();
 		$this->assertEquals(array('statut' => 1,
 															'erreur' => ''),
 												$this->comm_sigb->reserverExemplaire(5, '123', 'ABC'));
@@ -346,14 +346,18 @@ class CommSigbMoulinsVSmartTest extends CommSigbTestCase {
 class CommSigbMeuseKohaTest extends CommSigbTestCase {
 	public function setUp() {
 		parent::setUp();
+		
+		$params = ['url_serveur' => 'http://cat-aficg55.biblibre.com/cgi-bin/koha/ilsdi.pl'];
 
 		$this->bib_koha = Class_IntBib::getLoader()
 			->newInstanceWithId(5)
-			->setCommParams(array("url_serveur" => 'http://cat-aficg55.biblibre.com/cgi-bin/koha/ilsdi.pl'))
+			->setCommParams($params)
 			->setCommSigb(5);
 
-
-		Class_WebService_SIGB_Koha::setService($this->createMockForService('Koha'));
+		Class_WebService_SIGB_Koha::setService(array_merge($params,
+																											 ['id_bib' => 5,
+																												'type' => Class_IntBib::COM_KOHA]),
+																					 $this->createMockForService('Koha'));
 	}
 
 
-- 
GitLab