diff --git a/application/modules/opac/controllers/RssController.php b/application/modules/opac/controllers/RssController.php index b868e5338b3b9867d183e416444f7b60ef1ce1e4..cd8a0763ada37fd30a7fb691c7c99edb831e52bd 100644 --- a/application/modules/opac/controllers/RssController.php +++ b/application/modules/opac/controllers/RssController.php @@ -153,7 +153,7 @@ class RssController extends Zend_Controller_Action } else { - $httpClient = Zend_Registry::get('httpClient'); + $httpClient = Class_HttpClientFactory::getInstance()->newHttpClient(); try { Zend_Feed::setHttpClient($httpClient); diff --git a/library/Class/Cosmogramme/Integration/PhaseBatchs.php b/library/Class/Cosmogramme/Integration/PhaseBatchs.php index e59cc2b5b251523c0b4df432cb7d04ee12120448..43e258cb91036b7bc31993bfa7d4016fbda97d79 100644 --- a/library/Class/Cosmogramme/Integration/PhaseBatchs.php +++ b/library/Class/Cosmogramme/Integration/PhaseBatchs.php @@ -42,22 +42,13 @@ class Class_Cosmogramme_Integration_PhaseBatchs if ($this->_getData('pointeur_reprise') > $batch->getId()) continue; - $this->_resetHttpClient() - ->_runOne($batch); + $this->_runOne($batch); $this->_cleanMemory(); } } - protected function _resetHttpClient() { - if (!$client = Zend_Registry::get('httpClient')) - return $this; - - $client->setAuth(null); - return $this; - } - protected function _runOne($batch) { if (!$batch->shouldRun()) { diff --git a/library/Class/HttpClientFactory.php b/library/Class/HttpClientFactory.php new file mode 100644 index 0000000000000000000000000000000000000000..47e342845b2f72bfd032eab5be5ce106f344efb4 --- /dev/null +++ b/library/Class/HttpClientFactory.php @@ -0,0 +1,66 @@ +<?php +/** + * Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Class_HttpClientFactory { + protected static + $instance, + $adapter; + + protected + $_last_client; + + + public static function getInstance() { + return static::$instance ? static::$instance : (static::$instance = new static()); + } + + + public static function setInstance($instance) { + static::$instance = $instance; + } + + + public static function resetInstance() { + static::$instance = null; + } + + + public static function setAdapter($adapter) { + static::$adapter = $adapter; + } + + public function newHttpClient() { + $client = new Zend_Http_Client(); + if (static::$adapter) + $client->setAdapter(static::$adapter); + + $client->setConfig(['timeout' => 2]); + return $this->_last_client = $client; + } + + + public function getLastHttpClient() { + return $this->_last_client; + } + +} +?> \ No newline at end of file diff --git a/library/Class/Rss.php b/library/Class/Rss.php index efbf54bb1a1ab8dca04b616d5722bb57c51bc0ad..1dbdf3dd7146faba9c7ab105ccadc9ab57d60c45 100644 --- a/library/Class/Rss.php +++ b/library/Class/Rss.php @@ -198,7 +198,7 @@ class Class_Rss extends Storm_Model_Abstract { public function loadFeedItems() { $this->_feed_items = array(); - ZendAfi_Feed::setHttpClient(Zend_Registry::get('httpClient')); + ZendAfi_Feed::setHttpClient(Class_HttpClientFactory::getInstance()->newHttpClient()); $feed = ZendAfi_Feed::import($this->getUrl()); foreach($feed as $item) diff --git a/library/Class/WebService/Abstract.php b/library/Class/WebService/Abstract.php index ddb1052ef6b698e784389b1ae62d1c875a8112b6..cacabfd746c4f28a651997adb66f682c52d510e8 100644 --- a/library/Class/WebService/Abstract.php +++ b/library/Class/WebService/Abstract.php @@ -43,8 +43,9 @@ class Class_WebService_Abstract { } - public function httpGet($url) { - return $this->getHttpClient()->open_url($url); + public function httpGet($url,$options = []) { + $params = array_filter([$url,$options]); + return call_user_func_array([$this->getHttpClient(),'open_url'],$params); // avoid mocking of 2nd parameters } } diff --git a/library/Class/WebService/Babelio.php b/library/Class/WebService/Babelio.php index 1bfb9d8d2c782a848a4c9e16b00551ec9b22a9ea..993d271fa245f87c929baa114154a775a03ef0a3 100644 --- a/library/Class/WebService/Babelio.php +++ b/library/Class/WebService/Babelio.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class Class_WebService_Babelio { const USER = 'afi_test'; @@ -45,7 +45,7 @@ class Class_WebService_Babelio { * Par défaut désactivé. * babelio.expire_at = 2010/08/23 //expire à la date indiquée * babelio.expire_at = never // n'expire jamais - * + * * @return array */ public static function getActivationStatus() { @@ -59,7 +59,7 @@ class Class_WebService_Babelio { } $expire_at = $babelio->get('expire_at', null); - + if ($expire_at === 'never') { $status['enabled'] = true; return $status; @@ -74,7 +74,7 @@ class Class_WebService_Babelio { $status['enabled'] = $expiration_date->compare(new Zend_Date()) > 0; return $status; } - + /** * @param string $isbn @@ -105,7 +105,7 @@ class Class_WebService_Babelio { */ public function getHttpClient() { if (null === $this->_httpClient) { - $this->_httpClient = Zend_Registry::get('httpClient'); + $this->_httpClient = Class_HttpClientFactory::getInstance()->newHttpClient(); } return $this->_httpClient; @@ -154,7 +154,7 @@ class Class_WebService_Babelio { return $status['enabled']; } - + /** * @param Class_Notice $notice */ diff --git a/library/Class/WebService/BibNumerique/ArteVOD.php b/library/Class/WebService/BibNumerique/ArteVOD.php index 444fa7fd43cf5c2b469e43c3682311e9c7670300..8cc3d2f58e6f674f41556493d919cf427a18dd0b 100644 --- a/library/Class/WebService/BibNumerique/ArteVOD.php +++ b/library/Class/WebService/BibNumerique/ArteVOD.php @@ -41,9 +41,8 @@ class Class_WebService_BibNumerique_ArteVOD extends Class_WebService_BibNumeriqu public function open_authenticated_url($url) { - $this->getWebClient()->setAuth(Class_AdminVar::get('ARTE_VOD_LOGIN'), - Class_AdminVar::get('ARTE_VOD_KEY')); - return $this->getWebClient()->open_url($url); + return $this->getWebClient()->open_url($url, ['auth' => ['user' => Class_AdminVar::get('ARTE_VOD_LOGIN'), + 'password' => Class_AdminVar::get('ARTE_VOD_KEY')]]); } diff --git a/library/Class/WebService/BibNumerique/Dilicom/Hub.php b/library/Class/WebService/BibNumerique/Dilicom/Hub.php index e72e86c484877bc2736729233a9e1948af52cf80..e89e25f5771983bbcee93e4c71e63a7954c9e162 100644 --- a/library/Class/WebService/BibNumerique/Dilicom/Hub.php +++ b/library/Class/WebService/BibNumerique/Dilicom/Hub.php @@ -245,13 +245,9 @@ class Class_WebService_BibNumerique_Dilicom_Hub extends Class_WebService_Abstrac protected function dilicomCall($service, $params) { - static::getHttpClient() - ->setAuth(Class_AdminVar::get('DILICOM_PNB_GLN_COLLECTIVITE'), - Class_AdminVar::get('DILICOM_PNB_PWD_COLLECTIVITE')); - - $data = $this->httpGet($this->buildUrl($service, $params)); - static::getHttpClient()->setAuth(null); - return $data; + return $this->httpGet($this->buildUrl($service, $params), + ['auth' => ['user' =>Class_AdminVar::get('DILICOM_PNB_GLN_COLLECTIVITE'), + 'password' => Class_AdminVar::get('DILICOM_PNB_PWD_COLLECTIVITE')]]); } diff --git a/library/Class/WebService/Premiere.php b/library/Class/WebService/Premiere.php index 9bbca85d110cbb54bed6565d2d45ec3ec29fca64..722cc0181afc2f3d1f657b67f98a0ddc396802ba 100644 --- a/library/Class/WebService/Premiere.php +++ b/library/Class/WebService/Premiere.php @@ -53,7 +53,7 @@ class Class_WebService_Premiere { $url=str_replace("@TITRE@",$titre,$this->url_base["resume"]); // Get http de la page try{ - $httpClient = Zend_Registry::get('httpClient'); + $httpClient = Class_HttpClientFactory::getInstance()->newHttpClient(); $httpClient->setUri($url); $response = $httpClient->request(); $data = $response->getBody(); @@ -81,7 +81,7 @@ class Class_WebService_Premiere { $url=str_replace("@TITRE@",$titre,$this->url_base["image"]); // Get http de la page try{ - $httpClient = Zend_Registry::get('httpClient'); + $httpClient = Class_HttpClientFactory::getInstance()->newHttpClient(); $httpClient->setUri($url); $response = $httpClient->request(); $data = $response->getBody(); diff --git a/library/Class/WebService/SIGB/Koha/Service.php b/library/Class/WebService/SIGB/Koha/Service.php index c819f17ca9e15732e04920f75381145853a3b8c0..ce9be047508026b19b95db52cdb1d079b9ad90b4 100644 --- a/library/Class/WebService/SIGB/Koha/Service.php +++ b/library/Class/WebService/SIGB/Koha/Service.php @@ -239,7 +239,8 @@ class Class_WebService_SIGB_Koha_Service extends Class_WebService_SIGB_AbstractR try { $this->getNotice(1); - $httpClient = $this->getWebClient()->getHttpClient(); + $httpClient = $this->getWebClient(); + $message = $httpClient->getLastRequest(); if ($response = $httpClient->getLastResponse()) $message .= $response->getStatus() . " " . $response->getMessage() diff --git a/library/Class/WebService/SIGB/PMB/Service.php b/library/Class/WebService/SIGB/PMB/Service.php index 0bfdb5a5481d7f8fa87da8a689ac76d7db524f82..4f4e5923e57e896cf11f449aa0b573a4dec87b7f 100644 --- a/library/Class/WebService/SIGB/PMB/Service.php +++ b/library/Class/WebService/SIGB/PMB/Service.php @@ -305,7 +305,7 @@ class JsonWebClient { public function getHttpClient() { if(!$this->_http_client) { - $this->_http_client = Zend_Registry::get('httpClient'); + $this->_http_client = Class_HttpClientFactory::getInstance()->newHttpClient(); } return $this->_http_client; } diff --git a/library/Class/WebService/SimpleWebClient.php b/library/Class/WebService/SimpleWebClient.php index 6dc885fd0c71d382fcd6243564adcf7c3ae15622..88ad992c0d5d7e53715fbe53402ebc1360eacffa 100644 --- a/library/Class/WebService/SimpleWebClient.php +++ b/library/Class/WebService/SimpleWebClient.php @@ -23,17 +23,22 @@ class Class_WebService_SimpleWebClient { use Trait_Singleton; + protected + $_last_http_client; + public function getHttpClient() { - return Zend_Registry::get('httpClient'); + return $this->_last_http_client = Class_HttpClientFactory::getInstance()->newHttpClient(); } - public function open_url($url,$headers = []) { - + public function open_url($url,$options = []) { $httpClient = $this->getHttpClient(); - $httpClient->resetParameters(); - if (count($headers)>0) - $httpClient->setHeaders($headers); + + if (isset($options['headers'])) + $httpClient->setHeaders($options['headers']); + if (isset($options['auth'])) + $httpClient->setAuth($options['auth']['user'], $options['auth']['password']); + $httpClient->setMethod(Zend_Http_Client::GET); $httpClient->setUri($url); $response = $httpClient->request(); @@ -41,12 +46,6 @@ class Class_WebService_SimpleWebClient { } - public function setAuth($user, $pass='') { - $httpClient = Zend_Registry::get('httpClient'); - $httpClient->setAuth($user, $pass); - } - - public function postData($url, $params) { $httpClient = $this->getHttpClient(); $httpClient->resetParameters(); @@ -58,6 +57,20 @@ class Class_WebService_SimpleWebClient { return $httpClient->request()->getBody(); } + + + public function getLastRequest() { + return $this->_last_http_client + ? $this->_last_http_client->getLastRequest() + : null; + } + + + public function getLastResponse() { + return $this->_last_http_client + ? $this->_last_http_client->getLastResponse() + : null; + } } ?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/InspectorGadget.php b/library/ZendAfi/Controller/Plugin/InspectorGadget.php index 03078e3990a05a2128c85199d01bf3d66728f33b..be9940e4ad83a2fcade4eb0bbb0f3381bacb2ffc 100644 --- a/library/ZendAfi/Controller/Plugin/InspectorGadget.php +++ b/library/ZendAfi/Controller/Plugin/InspectorGadget.php @@ -143,7 +143,7 @@ onclick="$(\'[data-type=' . self::PARAM_NAME . '-' . $content . ']\').dialog({ti public function log() { - $httpClient = Zend_Registry::get('httpClient'); + $httpClient = Class_HttpClientFactory::getInstance()->getLastHttpClient(); $response_code = $response_body = null; if ($response = $httpClient->getLastResponse()) { $response_code = $response->getStatus(); diff --git a/library/digital_resources/Skilleos/Service.php b/library/digital_resources/Skilleos/Service.php index 304e766c411afc993fca2b8785955290bbab0141..2e39965e4859cc5836b0347d6725878c19422b63 100644 --- a/library/digital_resources/Skilleos/Service.php +++ b/library/digital_resources/Skilleos/Service.php @@ -45,7 +45,7 @@ class Skilleos_Service extends Class_DigitalResource_Service { $client = $this->getHttpClient(); $json = json_decode($client->open_url(static::$REST_URL, - [ 'Authorization' => 'Bearer '.$token])); + ['headers' => [ 'Authorization' => 'Bearer '.$token]])); foreach ($json as $result) { $this->_albums[] = new Skilleos_Service_Parser($result); diff --git a/library/digital_resources/Skilleos/tests/SkilleosTest.php b/library/digital_resources/Skilleos/tests/SkilleosTest.php index df984d985221b9601a6905998a3593dcb6d11e8a..544ddfea930066edbc7b8d5f39c4582f0aaf2b60 100644 --- a/library/digital_resources/Skilleos/tests/SkilleosTest.php +++ b/library/digital_resources/Skilleos/tests/SkilleosTest.php @@ -214,7 +214,7 @@ abstract class SkilleosServiceTestCase extends AbstractControllerTestCase { ->answers($token_json) ->whenCalled('open_url') ->with('http://moncompte.skilleos.com/rest/api/trainings', - ['Authorization' => "Bearer YTEzMDA1M2Q1ZGRmYmE0YjJkNWQ3MGY3ZGUyYTI3ZWJkMjBjOGI2NzIzMDIzMDc0MDAyYTE0NGJjMTRmMzkzMg"]) + ['headers' => ['Authorization' => "Bearer YTEzMDA1M2Q1ZGRmYmE0YjJkNWQ3MGY3ZGUyYTI3ZWJkMjBjOGI2NzIzMDIzMDc0MDAyYTE0NGJjMTRmMzkzMg"]]) ->answers($results_json) ->whenCalled('open_url') ->with('https://moncompte.skilleos.com/uploads/ressources/default/0001/11/thumb_10683_default_big.png') diff --git a/library/startup.php b/library/startup.php index fdcaa1de73a9c823e43a5e957f9097844caf4027..6443601431e89b96a1f8c4a7ab51e3e2747b30be 100644 --- a/library/startup.php +++ b/library/startup.php @@ -247,7 +247,6 @@ class Bokeh_Engine { function setupHTTPClient() { - $httpClient = new Zend_Http_Client(); if ( (isset ($this->_config->proxy->host) ) && ($this->_config->proxy->host != '') ){ //set up HTTP Client to use proxy settings @@ -261,12 +260,9 @@ class Bokeh_Engine { $proxy_adapter = new Zend_Http_Client_Adapter_Proxy(); $proxy_adapter->setConfig($proxy_config); - $httpClient->setAdapter($proxy_adapter); + Class_HttpClientFactory::setAdapter($proxy_adapter); } - $httpClient->setConfig(['timeout' => 2]); - - Zend_Registry::set('httpClient',$httpClient); return $this; } diff --git a/tests/application/modules/opac/controllers/AbonneControllerPretsTest.php b/tests/application/modules/opac/controllers/AbonneControllerPretsTest.php index 409cd3e39abbd09a2a5004635297266503eba0b3..5fdc364bb0d73240ebaa33814af27a8a45628b59 100644 --- a/tests/application/modules/opac/controllers/AbonneControllerPretsTest.php +++ b/tests/application/modules/opac/controllers/AbonneControllerPretsTest.php @@ -73,17 +73,8 @@ abstract class AbstractAbonneControllerPretsTestCase extends AbstractControllerT 'valeur' => '777']); $this->_http = $this->mock() - ->whenCalled('setAuth') - ->with('test-gln', 'test-gln-pass') - ->answers(null) - - ->whenCalled('setAuth') - ->with(null) - ->answers(null) - ->whenCalled('open_url') ->answers('') - ->whenCalled('open_url') ->with('/v2/pnb-numerique/json/getEndedLoans?glnContractor=777&loanId[0]=5') ->answers(DilicomFixtures::getEndedLoansResponse()) @@ -476,7 +467,9 @@ class AbonneControllerPretsListThreePretsPnbEarlyReturnTest extends AbonneContro $this->_http ->whenCalled('open_url') - ->with('/v2/pnb-numerique/json/getEndedLoans?glnContractor=777&loanId[0]=5&loanId[1]=6') + ->with('/v2/pnb-numerique/json/getEndedLoans?glnContractor=777&loanId[0]=5&loanId[1]=6', + ['auth' => ['user' => 'test-gln', + 'password' => 'test-gln-pass']]) ->answers(DilicomFixtures::getEndedLoansResponse(['{"loanId":"5","returnDate":"2015-09-18T14:30:00+02:00"}'])) ->beStrict(); diff --git a/tests/application/modules/opac/controllers/BibNumeriqueControllerDilicomTest.php b/tests/application/modules/opac/controllers/BibNumeriqueControllerDilicomTest.php index ac9901d033768ec2a268286c967021fe03dc42b4..ac5e66d991138db7c3bf4f5de15142e3f2f14090 100644 --- a/tests/application/modules/opac/controllers/BibNumeriqueControllerDilicomTest.php +++ b/tests/application/modules/opac/controllers/BibNumeriqueControllerDilicomTest.php @@ -88,16 +88,10 @@ abstract class BibNumeriqueContollerDilicomTestCase extends AbstractControllerTe Class_WebService_BibNumerique_Dilicom_Hub::setDefaultHttpClient($this->_http); $this->_http - ->whenCalled('setAuth') - ->with(null) - ->answers(null) - - ->whenCalled('setAuth') - ->with('afi-bib', 'secretPassword') - ->answers(null) - ->whenCalled('open_url') - ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/getLoanStatus?glnContractor=123456789&orderLineId[0]=x321') + ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/getLoanStatus?glnContractor=123456789&orderLineId[0]=x321', + ['auth' => [ 'user' => 'afi-bib', + 'password' => 'secretPassword']]) ->answers(DilicomFixtures::getLoanStatusResponse()); @@ -128,7 +122,9 @@ class BibNumeriqueContollerDilicomAjaxPopupBookActionTest extends BibNumeriqueCo public function popupConsultBookShouldContainsLinkToOpenAjax() { $this->_http ->whenCalled('open_url') - ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/consultBook?glnContractor=123456789&orderLineId=x321&accessMedium=STREAMING&localization=IN_SITU&consultEndDate=2014-05-02T15%3A14%3A14%2B0200&ean13=435465&ipAddress=127.0.0.1&glnColl=afi-bib&loanerColl=2345889&loanId=n4y4nq63') + ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/consultBook?glnContractor=123456789&orderLineId=x321&accessMedium=STREAMING&localization=IN_SITU&consultEndDate=2014-05-02T15%3A14%3A14%2B0200&ean13=435465&ipAddress=127.0.0.1&glnColl=afi-bib&loanerColl=2345889&loanId=n4y4nq63', + ['auth' => [ 'user' => 'afi-bib', + 'password' => 'secretPassword']]) ->answers(DilicomFixtures::loanBookResponse()) ->beStrict(); @@ -142,7 +138,9 @@ class BibNumeriqueContollerDilicomAjaxPopupBookActionTest extends BibNumeriqueCo public function popupConsultBookOpenShouldContainsLinkToOpenPnbUrl() { $this->_http ->whenCalled('open_url') - ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/consultBook?glnContractor=123456789&orderLineId=x321&accessMedium=STREAMING&localization=IN_SITU&consultEndDate=2014-05-02T15%3A14%3A14%2B0200&ean13=435465&ipAddress=127.0.0.1&glnColl=afi-bib&loanerColl=2345889&loanId=n4y4nq63') + ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/consultBook?glnContractor=123456789&orderLineId=x321&accessMedium=STREAMING&localization=IN_SITU&consultEndDate=2014-05-02T15%3A14%3A14%2B0200&ean13=435465&ipAddress=127.0.0.1&glnColl=afi-bib&loanerColl=2345889&loanId=n4y4nq63', + ['auth' => [ 'user' => 'afi-bib', + 'password' => 'secretPassword']]) ->answers(DilicomFixtures::loanBookResponse()) ->beStrict(); @@ -156,7 +154,9 @@ class BibNumeriqueContollerDilicomAjaxPopupBookActionTest extends BibNumeriqueCo public function popupLoanBookOpenAjaxWithPnbErrorShouldContainsScriptToReloadPage() { $this->_http ->whenCalled('open_url') - ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/consultBook?glnContractor=123456789&orderLineId=x321&accessMedium=STREAMING&localization=IN_SITU&consultEndDate=2014-05-02T15%3A14%3A14%2B0200&ean13=435465&ipAddress=127.0.0.1&glnColl=afi-bib&loanerColl=2345889&loanId=n4y4nq63') + ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/consultBook?glnContractor=123456789&orderLineId=x321&accessMedium=STREAMING&localization=IN_SITU&consultEndDate=2014-05-02T15%3A14%3A14%2B0200&ean13=435465&ipAddress=127.0.0.1&glnColl=afi-bib&loanerColl=2345889&loanId=n4y4nq63', + ['auth' => [ 'user' => 'afi-bib', + 'password' => 'secretPassword']]) ->answers(DilicomFixtures::loanBookErrorResponse()) ->beStrict(); @@ -209,7 +209,9 @@ class BibNumeriqueContollerDilicomAjaxPopupBookActionTest extends BibNumeriqueCo public function downloadLinkShouldAnswersDilicomLink() { $this->_http ->whenCalled('open_url') - ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/loanBook?glnContractor=123456789&orderLineId=x321&accessMedium=DOWNLOAD&glnColl=afi-bib&loanerColl=2345889&localization=EX_SITU&loanEndDate=2014-08-10T14%3A14%3A14%2B0200&ean13=435465&loanId=1') + ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/loanBook?glnContractor=123456789&orderLineId=x321&accessMedium=DOWNLOAD&glnColl=afi-bib&loanerColl=2345889&localization=EX_SITU&loanEndDate=2014-08-10T14%3A14%3A14%2B0200&ean13=435465&loanId=1', + ['auth' => [ 'user' => 'afi-bib', + 'password' => 'secretPassword']]) ->answers(DilicomFixtures::loanBookResponse()) ->beStrict(); @@ -222,7 +224,9 @@ class BibNumeriqueContollerDilicomAjaxPopupBookActionTest extends BibNumeriqueCo public function downloadLinkWithPnbErrorShouldConstainsScriptToReloadPage() { $this->_http ->whenCalled('open_url') - ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/loanBook?glnContractor=123456789&orderLineId=x321&accessMedium=DOWNLOAD&glnColl=afi-bib&loanerColl=2345889&localization=EX_SITU&loanEndDate=2014-08-10T14%3A14%3A14%2B0200&ean13=435465&loanId=1') + ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/loanBook?glnContractor=123456789&orderLineId=x321&accessMedium=DOWNLOAD&glnColl=afi-bib&loanerColl=2345889&localization=EX_SITU&loanEndDate=2014-08-10T14%3A14%3A14%2B0200&ean13=435465&loanId=1', + ['auth' => [ 'user' => 'afi-bib', + 'password' => 'secretPassword']]) ->answers(DilicomFixtures::loanBookErrorResponse()) ->beStrict(); @@ -256,7 +260,9 @@ class BibNumeriqueContollerDilicomConsultBookActionTest extends BibNumeriqueCont .'&ipAddress=195.251.88.223' .'&glnColl=afi-bib' .'&loanerColl=2345889' - .'&loanId='.base_convert($this->_time_source->time(), 10, 36).'63') + .'&loanId='.base_convert($this->_time_source->time(), 10, 36).'63', + ['auth' => [ 'user' => 'afi-bib', + 'password' => 'secretPassword']]) ->answers('{"orderLineId":"54e7473f975a2fa6aa4d3e17","consultEndDate":"2014-05-02T15:14:14+0200","loanId":"3","returnStatus":"OK","returnMessage":[],"requestId":"awvzrcttestpnbv2_000000039_201503051511","link":{"url":"https://pnb-test.centprod.com/v2//link/3056000302801/CONSULT/3/9791023501766-FGR9FJJGJCMXYMB8BO87XR9TPHDN9QNS.do","aformatDescription":"EPUB","mimetype":"application/epub+zip","ean13":"9791023501766","format":"E101"}}') ->beStrict(); @@ -280,11 +286,6 @@ class BibNumeriqueContollerDilicomConsultBookActionTest extends BibNumeriqueCont } - /** @test */ - public function setAuthShouldHaveBeenCalled() { - $this->assertTrue($this->_http->methodHasBeenCalled('setAuth')); - } - /** @test */ public function responseShouldRedirectToConsultBookUrl() { @@ -335,17 +336,23 @@ class BibNumeriqueControllerDilicomLoanBookActionTestCase extends BibNumeriqueCo $this->_http ->whenCalled('open_url') - ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/loanBook?glnContractor=123456789&orderLineId=x321&accessMedium=DOWNLOAD&glnColl=afi-bib&loanerColl=2345889&localization=EX_SITU&loanEndDate=2014-08-10T14%3A14%3A14%2B0200&ean13=435465&loanId=1') + ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/loanBook?glnContractor=123456789&orderLineId=x321&accessMedium=DOWNLOAD&glnColl=afi-bib&loanerColl=2345889&localization=EX_SITU&loanEndDate=2014-08-10T14%3A14%3A14%2B0200&ean13=435465&loanId=1', + ['auth' => [ 'user' => 'afi-bib', + 'password' => 'secretPassword']]) ->answers(DilicomFixtures::loanBookResponse()) ->whenCalled('open_url') - ->with($update_status_url) + ->with($update_status_url, + ['auth' => [ 'user' => 'afi-bib', + 'password' => 'secretPassword']]) ->willDo(function() use ($update_status_url) { $this->_http ->whenCalled('open_url') - ->with($update_status_url) + ->with($update_status_url, + ['auth' => [ 'user' => 'afi-bib', + 'password' => 'secretPassword']]) ->answers(DilicomFixtures::getLoanStatusAfterLoanResponse()); return DilicomFixtures::getLoanStatusResponse(); }) @@ -405,7 +412,9 @@ class BibNumeriqueControllerDilicomLoanBookActionErrorsTest extends BibNumerique $this->_http ->whenCalled('open_url') - ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/loanBook?glnContractor=123456789&orderLineId=x321&accessMedium=DOWNLOAD&glnColl=afi-bib&loanerColl=2345889&localization=EX_SITU&loanEndDate=2014-05-12T14%3A14%3A14%2B0200&ean13=435465&loanId=1') + ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/loanBook?glnContractor=123456789&orderLineId=x321&accessMedium=DOWNLOAD&glnColl=afi-bib&loanerColl=2345889&localization=EX_SITU&loanEndDate=2014-05-12T14%3A14%3A14%2B0200&ean13=435465&loanId=1', + ['auth' => [ 'user' => 'afi-bib', + 'password' => 'secretPassword']]) ->answers(DilicomFixtures::loanBookErrorResponse()) ->beStrict(); @@ -454,7 +463,9 @@ class BibNumeriqueControllerDilicomLoanBookActionTwiceWithSameUserTest extends B $this->_http ->whenCalled('open_url') - ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/getEndedLoans?glnContractor=123456789&loanId[0]=5') + ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/getEndedLoans?glnContractor=123456789&loanId[0]=5', + ['auth' => [ 'user' => 'afi-bib', + 'password' => 'secretPassword']]) ->answers(DilicomFixtures::getEndedLoansResponse()) ->beStrict(); @@ -509,7 +520,9 @@ class BibNumeriqueControllerDilicomLoanBookActionWithASecondUserAndLoanCountExce $this->_http ->whenCalled('open_url') - ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/getLoanStatus?glnContractor=123456789&orderLineId[0]=x321') + ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/getLoanStatus?glnContractor=123456789&orderLineId[0]=x321', + ['auth' => [ 'user' => 'afi-bib', + 'password' => 'secretPassword']]) ->answers(DilicomFixtures::getLoanStatusNoSimultaneousLoanLeftResponse()) ->beStrict(); @@ -562,7 +575,9 @@ class BibNumeriqueControllerDilicomLoanBookActionWithTwoItemsTest extends BibNum parent::setUp(); $this->_http ->whenCalled('open_url') - ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/getLoanStatus?glnContractor=123456789&orderLineId[0]=x458') + ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/getLoanStatus?glnContractor=123456789&orderLineId[0]=x458', + ['auth' => [ 'user' => 'afi-bib', + 'password' => 'secretPassword']]) ->answers(DilicomFixtures::getLoanStatusResponse()); $this->book->addItem( @@ -603,7 +618,9 @@ class BibNumeriqueControllerDilicomLoanBookActionWithTwoItemsTest extends BibNum $this->_http ->whenCalled('open_url') - ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/loanBook?glnContractor=123456789&orderLineId=x458&accessMedium=DOWNLOAD&glnColl=afi-bib&loanerColl=2345889&localization=EX_SITU&loanEndDate=2015-07-20T00%3A00%3A00%2B0200&ean13=435465&loanId=1') + ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/loanBook?glnContractor=123456789&orderLineId=x458&accessMedium=DOWNLOAD&glnColl=afi-bib&loanerColl=2345889&localization=EX_SITU&loanEndDate=2015-07-20T00%3A00%3A00%2B0200&ean13=435465&loanId=1', + ['auth' => [ 'user' => 'afi-bib', + 'password' => 'secretPassword']]) ->answers(DilicomFixtures::loanBookResponse()); $this->_dispatchAndAssertSecondBookLoaned(); @@ -614,11 +631,15 @@ class BibNumeriqueControllerDilicomLoanBookActionWithTwoItemsTest extends BibNum public function withFirstItemLoandCountExcededShouldLoanSecondItem() { $this->_http ->whenCalled('open_url') - ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/getLoanStatus?glnContractor=123456789&orderLineId[0]=x321') + ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/getLoanStatus?glnContractor=123456789&orderLineId[0]=x321', + ['auth' => [ 'user' => 'afi-bib', + 'password' => 'secretPassword']]) ->answers(DilicomFixtures::getLoanStatusNoSimultaneousLoanLeftResponse()) ->whenCalled('open_url') - ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/loanBook?glnContractor=123456789&orderLineId=x458&accessMedium=DOWNLOAD&glnColl=afi-bib&loanerColl=2345889&localization=EX_SITU&loanEndDate=2014-05-12T14%3A14%3A14%2B0200&ean13=435465&loanId=1') + ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/loanBook?glnContractor=123456789&orderLineId=x458&accessMedium=DOWNLOAD&glnColl=afi-bib&loanerColl=2345889&localization=EX_SITU&loanEndDate=2014-05-12T14%3A14%3A14%2B0200&ean13=435465&loanId=1', + ['auth' => [ 'user' => 'afi-bib', + 'password' => 'secretPassword']]) ->answers(DilicomFixtures::loanBookResponse()); $this->_dispatchAndAssertSecondBookLoaned(); @@ -707,7 +728,9 @@ class BibNumeriqueControllerDilicomLoanBookActionWithASecondUserAndQuantityExced parent::setUp(); $this->_http ->whenCalled('open_url') - ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/getLoanStatus?glnContractor=123456789&orderLineId[0]=x321') + ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/getLoanStatus?glnContractor=123456789&orderLineId[0]=x321', + ['auth' => [ 'user' => 'afi-bib', + 'password' => 'secretPassword']]) ->answers(DilicomFixtures::getLoanStatusNoQuantityLeftResponse()); $this->dispatch('/bib-numerique/loan-book/id/3', true); diff --git a/tests/application/modules/opac/controllers/RssControllerTest.php b/tests/application/modules/opac/controllers/RssControllerTest.php index bc72e30f2c34b532e94bb7d87ea1e1c6abb6b9e9..dab2e443bdf44458bc807f12806624a004b6f04d 100644 --- a/tests/application/modules/opac/controllers/RssControllerTest.php +++ b/tests/application/modules/opac/controllers/RssControllerTest.php @@ -60,19 +60,11 @@ class RssControllerViewRawRssTest extends AbstractControllerTestCase { 'preferences' => $preferences)))); - - $this->old_http_client = Zend_Registry::get('httpClient'); - Zend_Registry::set('httpClient', new MockZendHttpClient()); - + Class_HttpClientFactory::setInstance($this->mock()->whenCalled('newHttpClient')->answers(new MockZendHttpClient())); $this->dispatch('rss/view-raw-rss/id_rss/15/id_profil/25/id_module/1'); } - public function tearDown() { - Zend_Registry::set('httpClient', $this->old_http_client); - parent::tearDown(); - } - /** @test */ function titleShouldContainsBlogDelinquanceEtc() { diff --git a/tests/application/modules/telephone/controllers/AbonneControllerTest.php b/tests/application/modules/telephone/controllers/AbonneControllerTest.php index 66b8f1e078d29b8618d2badbbd9416cb8fed524e..359a0dc6b49947dbb4a02dad428650bb26f33db0 100644 --- a/tests/application/modules/telephone/controllers/AbonneControllerTest.php +++ b/tests/application/modules/telephone/controllers/AbonneControllerTest.php @@ -183,11 +183,10 @@ class AbonneControllerTelephoneFicheWithPNBTest extends AbonneControllerTelephon 'expected_return_date' => '2022-05-02T18:14:14+02:00']); $http_client = $this->mock() - ->whenCalled('setAuth')->with(null, null)->answers(true) - ->whenCalled('setAuth')->with(null)->answers(true) - ->whenCalled('open_url') - ->with('/v2/pnb-numerique/json/getEndedLoans?glnContractor=&loanId[0]=42') + ->with('/v2/pnb-numerique/json/getEndedLoans?glnContractor=&loanId[0]=42', + ['auth' => [ 'user' => null, + 'password' => null]]) ->answers('') ->beStrict(); diff --git a/tests/library/Class/Batch/DilicomTest.php b/tests/library/Class/Batch/DilicomTest.php index a4bf4ee1b76976eea8c92f9807d69348539b14e2..26849883958a009c61354907e719cd7a89c6b6f2 100644 --- a/tests/library/Class/Batch/DilicomTest.php +++ b/tests/library/Class/Batch/DilicomTest.php @@ -546,7 +546,9 @@ class Class_Batch_DilicomJobEndedLoansNoUpdatesTest $this->_http ->whenCalled('open_url') - ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/getEndedLoans?glnContractor=123456789&loanId[0]=12') + ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/getEndedLoans?glnContractor=123456789&loanId[0]=12', + ['auth' => [ 'user' => 'afi-bib', + 'password' => 'secretPassword']]) ->answers(DilicomFixtures::getEndedLoansResponse()); $this->_loadLoans(); @@ -585,7 +587,9 @@ class Class_Batch_DilicomJobEndedLoansWithUpdatesTest $this->_http ->whenCalled('open_url') - ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/getEndedLoans?glnContractor=123456789&loanId[0]=12') + ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/getEndedLoans?glnContractor=123456789&loanId[0]=12', + ['auth' => ['user' => 'afi-bib', + 'password' => 'secretPassword']]) ->answers(DilicomFixtures::getEndedLoansResponse(['{"loanId":"12","returnDate":"'. $this->_early_returned . '"}'])); diff --git a/tests/library/Class/Cosmogramme/Integration/PhaseBatchsTest.php b/tests/library/Class/Cosmogramme/Integration/PhaseBatchsTest.php index 1da13472e240efd5ae2f2ddfde5590bd4bee0993..a05d312d7c88996b37702028e9486f8a25bac305 100644 --- a/tests/library/Class/Cosmogramme/Integration/PhaseBatchsTest.php +++ b/tests/library/Class/Cosmogramme/Integration/PhaseBatchsTest.php @@ -65,11 +65,9 @@ abstract class PhaseBatchsTestCase extends Class_Cosmogramme_Integration_PhaseTe public function setUp() { parent::setUp(); - - $this->_registry_http_client = Zend_Registry::get('httpClient'); $this->_mock_http_client = $this->mock(); $this->_mock_http_client->whenCalled('setAuth')->answers($this->_mock_http_client); - Zend_Registry::set('httpClient', $this->_mock_http_client); + Class_HttpClientFactory::setInstance($this->mock()->whenCalled('newHttpClient')->answers($this->_mock_http_client)); $this->_buildPhase('Batchs')->run(); } @@ -77,7 +75,7 @@ abstract class PhaseBatchsTestCase extends Class_Cosmogramme_Integration_PhaseTe public function tearDown() { Class_Batch::setTimeSource(null); - Zend_Registry::set('httpClient', $this->_registry_http_client); + Class_HttpClientFactory::resetInstance(); parent::tearDown(); } } @@ -147,14 +145,6 @@ class PhaseBatchsCronRunTest extends PhaseBatchsTestCase { } - /** - * @test - * @see http://forge.afi-sa.fr/issues/28103 - */ - public function httpAuthShouldHaveBeenReset() { - $this->assertTrue($this->_mock_http_client - ->methodHasBeenCalled('setAuth')); - } } diff --git a/tests/library/Class/WebService/ArteVODTest.php b/tests/library/Class/WebService/ArteVODTest.php index 12e985cc251b25ac79346fde4197e4de1c8135c6..6990981a6a53cb66f37bb52485ba2e1c79fea209 100644 --- a/tests/library/Class/WebService/ArteVODTest.php +++ b/tests/library/Class/WebService/ArteVODTest.php @@ -41,8 +41,8 @@ abstract class ArteVODHarverstingTestCase extends ModelTestCase { ->newInstanceWithId('ARTE_VOD_KEY') ->setValeur('pass'); - $this->_web_client = Storm_Test_ObjectWrapper::mock() - ->whenCalled('setAuth')->with('user', 'pass')->answers(null); + $this->_web_client = Storm_Test_ObjectWrapper::mock(); + Class_WebService_BibNumerique_ArteVOD::setDefaultHttpClient($this->_web_client); @@ -59,17 +59,22 @@ class ArteVODHarverstingFourFilmsInTwoPages extends ArteVODHarverstingTestCase { public function setUp() { parent::setUp(); + $auth = ['auth' => [ 'user' => 'user', + 'password' => 'pass']]; $this->_web_client ->whenCalled('open_url') - ->with('https://vod.mediatheque-numerique.com/api/v1/films?page_nb=1') + ->with('https://vod.mediatheque-numerique.com/api/v1/films?page_nb=1', + $auth) ->answers(ArteVODFixtures::firstPage()) ->whenCalled('open_url') - ->with('https://vod.mediatheque-numerique.com/api/v1/films?page_nb=2') + ->with('https://vod.mediatheque-numerique.com/api/v1/films?page_nb=2', + $auth) ->answers(ArteVODFixtures::secondPage()) ->whenCalled('open_url') - ->with('https://vod.mediatheque-numerique.com/api/v1/films?page_nb=3') + ->with('https://vod.mediatheque-numerique.com/api/v1/films?page_nb=3', + $auth) ->answers('[]') ->beStrict(); diff --git a/tests/library/Class/WebService/Dilicom/HubTest.php b/tests/library/Class/WebService/Dilicom/HubTest.php index d2b8ddc6e21140b218191ae46d4d9a9b692fe57e..d162e17295eff57ec25abd48810d5c67d422a004 100644 --- a/tests/library/Class/WebService/Dilicom/HubTest.php +++ b/tests/library/Class/WebService/Dilicom/HubTest.php @@ -35,15 +35,6 @@ abstract class Class_Webservice_Dilicom_HubTestCase extends ModelTestCase { 'returnStatus' => 'OK', 'returnMessage' => []]); - $this->_http->whenCalled('setAuth') - ->with('afi-bib', 'secretPassword') - ->answers(null) - - ->whenCalled('setAuth') - ->with(null) - ->answers(null) - ->beStrict(); - $this->book = (new DilicomFixtures())->albumTotemThora(); } @@ -62,7 +53,9 @@ class Class_Webservice_Dilicom_HubDeclareIpTest extends Class_Webservice_Dilicom public function savingDilicomPnbIPAddressShouldCallWebserviceDeclareIP() { $this->_http->whenCalled('open_url') ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/declareIp?' - .'glnContractor=123456789&ips[0]=10.12.13.24') + .'glnContractor=123456789&ips[0]=10.12.13.24', + ['auth' => [ 'user' => 'afi-bib', + 'password' => 'secretPassword']]) ->answers($this->_response); $this->fixture('Class_AdminVar', @@ -70,7 +63,6 @@ class Class_Webservice_Dilicom_HubDeclareIpTest extends Class_Webservice_Dilicom 'valeur' => '10.12.13.24']); $this->assertTrue($this->_http->methodHasBeenCalled('open_url')); - $this->assertTrue($this->_http->methodHasBeenCalled('setAuth')); } @@ -78,7 +70,9 @@ class Class_Webservice_Dilicom_HubDeclareIpTest extends Class_Webservice_Dilicom public function savingDilicomPnbIpAdressWithMultipleIpsShouldCallWebServiceDeclareIp() { $this->_http->whenCalled('open_url') ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/declareIp?' - .'glnContractor=123456789&ips[0]=10.12.13.24&ips[1]=11.128.16.87') + .'glnContractor=123456789&ips[0]=10.12.13.24&ips[1]=11.128.16.87', + ['auth' => [ 'user' => 'afi-bib', + 'password' => 'secretPassword']]) ->answers($this->_response); $this->fixture('Class_AdminVar', @@ -100,7 +94,9 @@ class Class_Webservice_Dilicom_HubUpdateStatusSuccessfulTest extends Class_Webse $this->_http ->whenCalled('open_url') - ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/getLoanStatus?glnContractor=123456789&orderLineId[0]=x321') + ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/getLoanStatus?glnContractor=123456789&orderLineId[0]=x321', + ['auth' => [ 'user' => 'afi-bib', + 'password' => 'secretPassword']]) ->answers(DilicomFixtures::getLoanStatusResponse()) ->beStrict(); @@ -135,7 +131,9 @@ class Class_Webservice_Dilicom_HubUpdateStatusErrorTest extends Class_Webservice public function numberOfSimultaneousLoansRemaningShouldNotHaveBeenUpdatedOnError() { $this->_http ->whenCalled('open_url') - ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/getLoanStatus?glnContractor=123456789&orderLineId[0]=x321') + ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/getLoanStatus?glnContractor=123456789&orderLineId[0]=x321', + ['auth' => [ 'user' => 'afi-bib', + 'password' => 'secretPassword']]) ->answers(DilicomFixtures::getLoanStatusErrorResponse()) ->beStrict(); @@ -179,25 +177,17 @@ class Class_Webservice_Dilicom_UpdateLoansReturnDateTest extends Class_Webservic $this->_second_request = 'https://pnb-test.centprod.com/v2/pnb-numerique/json/getEndedLoans?glnContractor=123456789&loanId[0]=21&loanId[1]=22&loanId[2]=23&loanId[3]=24&loanId[4]=25&loanId[5]=26&loanId[6]=27&loanId[7]=28&loanId[8]=29&loanId[9]=30&loanId[10]=31&loanId[11]=32&loanId[12]=33&loanId[13]=34&loanId[14]=35'; $this->_http - ->whenCalled('open_url')->with($this->_first_request)->answers('') - ->whenCalled('open_url')->with($this->_second_request)->answers(''); + ->whenCalled('open_url')->with($this->_first_request, + ['auth' => [ 'user' => 'afi-bib', + 'password' => 'secretPassword']])->answers('') + ->whenCalled('open_url')->with($this->_second_request, + ['auth' => [ 'user' => 'afi-bib', + 'password' => 'secretPassword']])->answers('')->beStrict(); (new Class_WebService_BibNumerique_Dilicom_Hub())->updateLoansReturnDate($this->_loans); } - /** @test */ - public function httpRequestForFirstPageShouldHaveBeenSent() { - $this->assertTrue($this->_http->methodHasBeenCalledWithParams('open_url',[$this->_first_request])); - } - - - /** @test */ - public function httpRequestForSecondPageShouldHaveBeenSent() { - $this->assertTrue($this->_http->methodHasBeenCalledWithParams('open_url',[$this->_second_request])); - } - - /** @test */ public function httpRequestCountShouldBeTwo() { $this->assertEquals(2, $this->_http->methodCallCount('open_url')); diff --git a/tests/library/ZendAfi/View/Helper/Abonne/ResumeTest.php b/tests/library/ZendAfi/View/Helper/Abonne/ResumeTest.php index d958f24c7fe90760014e568a6d0b9ff71f69704b..e37903cd1bc566c9ba8708545d522576877313e0 100644 --- a/tests/library/ZendAfi/View/Helper/Abonne/ResumeTest.php +++ b/tests/library/ZendAfi/View/Helper/Abonne/ResumeTest.php @@ -64,16 +64,10 @@ class View_Helper_Abonne_ResumeAsAbonneSIGBTest extends ViewHelperTestCase { 'valeur' => '777']); $this->_http = $this->mock() - ->whenCalled('setAuth') - ->with('test-gln', 'test-gln-pass') - ->answers(null) - - ->whenCalled('setAuth') - ->with(null) - ->answers(null) - ->whenCalled('open_url') - ->with('/v2/pnb-numerique/json/getEndedLoans?glnContractor=777&loanId[0]=5&loanId[1]=6') + ->with('/v2/pnb-numerique/json/getEndedLoans?glnContractor=777&loanId[0]=5&loanId[1]=6', + ['auth' => [ 'user' => 'test-gln', + 'password' => 'test-gln-pass']]) ->answers(DilicomFixtures::getEndedLoansResponse()) ->beStrict(); diff --git a/tests/library/ZendAfi/View/Helper/Accueil/PretsTest.php b/tests/library/ZendAfi/View/Helper/Accueil/PretsTest.php index 4706358997ccde085bffdc4b546812c582d32bcc..c2cf816d1820b7048c9a0f644783c42820156c26 100644 --- a/tests/library/ZendAfi/View/Helper/Accueil/PretsTest.php +++ b/tests/library/ZendAfi/View/Helper/Accueil/PretsTest.php @@ -66,11 +66,10 @@ class PretsTestWithConnectedUser extends ViewHelperTestCase { 'expected_return_date' => '2022-05-02T18:14:14+02:00']); $http_client = $this->mock() - ->whenCalled('setAuth')->with(null, null)->answers(true) - ->whenCalled('setAuth')->with(null)->answers(true) - ->whenCalled('open_url') - ->with('/v2/pnb-numerique/json/getEndedLoans?glnContractor=&loanId[0]=12') + ->with('/v2/pnb-numerique/json/getEndedLoans?glnContractor=&loanId[0]=12', + ['auth' => [ 'user' => null, + 'password' => null]]) ->answers('') ->beStrict(); diff --git a/tests/library/ZendAfi/View/Helper/Status/TestCase.php b/tests/library/ZendAfi/View/Helper/Status/TestCase.php index 6d3f70b0ffd0f7f2928e37b1949a232c334c2413..86495e5022b48c18c92276da33687b31a255a511 100644 --- a/tests/library/ZendAfi/View/Helper/Status/TestCase.php +++ b/tests/library/ZendAfi/View/Helper/Status/TestCase.php @@ -186,13 +186,11 @@ abstract class ZendAfi_View_Helper_Status_TestCase extends ViewHelperTestCase { $time_source = new TimeSourceForTest('2016-12-05 11:00:00'); Class_Systeme_Report::setTimeSource($time_source); - $this->old_http_client = Zend_Registry::get('httpClient'); - Zend_Registry::set('httpClient', $this->mock()); } public function tearDown() { - Zend_Registry::set('httpClient', $this->old_http_client); + Class_HttpClientFactory::resetInstance(); parent::tearDown(); } } \ No newline at end of file