From c54a2ed48986f58f7eff2911b766b037c86f4582 Mon Sep 17 00:00:00 2001
From: Unknown <eric@sigmalis.com>
Date: Mon, 15 Jan 2018 17:42:15 +0100
Subject: [PATCH] =?UTF-8?q?Correction=20d'un=20probl=C3=A8me=20dans=20le?=
 =?UTF-8?q?=20tamponnage=20des=20actes=20sur=20les=20notifications=20~Acte?=
 =?UTF-8?q?s?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 CHANGELOG.md                               |  1 +
 class/PDFStampWrapper.class.php            | 27 ++++++++++++++--------
 test/PHPUnit/class/PDFStampWrapperTest.php | 13 +++++++----
 3 files changed, 27 insertions(+), 14 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 480f61bd6..8431b4ca9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,6 +22,7 @@ et adhère aux principes du [Semantic Versioning](http://semver.org/).
 - Typo dans le nom d'un script supervisor ~Actes #328
 - La signature par lot dans @ctes n'était plus fonctionnel ~Actes #334
 - Modification script supervisor pour éviter les warning #327
+- Correction d'un problème dans le tamponnage des actes sur les notifications ~Actes
 
 ## [3.0.1] - 2017-12-26
 
diff --git a/class/PDFStampWrapper.class.php b/class/PDFStampWrapper.class.php
index 6f79eafad..89a6a7df3 100644
--- a/class/PDFStampWrapper.class.php
+++ b/class/PDFStampWrapper.class.php
@@ -5,22 +5,29 @@ class PDFStampWrapper {
 
     private $pdf_stamp_url;
 
-    /** @var  CurlWrapper */
-    private $curlWrapper;
+    /** @var CurlWrapperFactory */
+    private $curlWrapperFactory;
 
     public function __construct($pdf_stamp_url) {
         $this->pdf_stamp_url = $pdf_stamp_url;
-        $this->setCurlWrapper(new CurlWrapper());
+        $this->setCurlWrapperFactory(new CurlWrapperFactory());
     }
 
-    public function setCurlWrapper(CurlWrapper $curlWrapper){
-        $this->curlWrapper = $curlWrapper;
+    public function setCurlWrapperFactory(CurlWrapperFactory $curlWrapperFactory){
+        $this->curlWrapperFactory = $curlWrapperFactory;
     }
 
+
     public function getLogoPath(){
         return __DIR__."/../public.ssl/custom/images/s2low-stamp.png";
     }
 
+    /**
+     * @param $pdf_filepath
+     * @param PDFStampData $pdfStampData
+     * @return bool|mixed
+     * @throws Exception
+     */
     public function stamp($pdf_filepath,PDFStampData $pdfStampData){
         $date_affichage = "";
         if ($pdfStampData->affichage_date){
@@ -62,14 +69,14 @@ class PDFStampWrapper {
         );
 
         /* curl -F "file=@Courrier.pdf" -F "metadata=$SAMPLE" -X POST http://pdf-stamp:8080 (!) */
-
-        $this->curlWrapper->addPostFile('file',$pdf_filepath);
-        $this->curlWrapper->addPostData('metadata',json_encode(utf8_encode_array($data)));
+        $curlWrapper = $this->curlWrapperFactory->getNewInstance();
+        $curlWrapper->addPostFile('file',$pdf_filepath);
+        $curlWrapper->addPostData('metadata',json_encode(utf8_encode_array($data)));
 
 
-        $result = $this->curlWrapper->get($this->pdf_stamp_url);
+        $result = $curlWrapper->get($this->pdf_stamp_url);
         if (!$result){
-            throw new Exception($this->curlWrapper->getLastError()." ".$this->curlWrapper->getLastOutput());
+            throw new Exception($curlWrapper->getLastError()." ".$curlWrapper->getLastOutput());
         }
         return $result;
     }
diff --git a/test/PHPUnit/class/PDFStampWrapperTest.php b/test/PHPUnit/class/PDFStampWrapperTest.php
index b6b06eb78..94d9b98e8 100644
--- a/test/PHPUnit/class/PDFStampWrapperTest.php
+++ b/test/PHPUnit/class/PDFStampWrapperTest.php
@@ -2,16 +2,21 @@
 
 class PDFStampWrapperTest extends PHPUnit_Framework_TestCase {
 
-    private function getCurlWrapper($return_string){
+    private function getCurlWrapperFactory($return_string){
         $curlWrapper = $this->getMockBuilder("CurlWrapper")->getMock();
         $curlWrapper->expects($this->any())->method("get")->willReturn($return_string);
-        /** @var CurlWrapper $curlWrapper */
-        return $curlWrapper;
+        $curlWrapperFactory = $this->getMockBuilder("CurlWrapperFactory")->getMock();
+        $curlWrapperFactory->expects($this->any())->method("getNewInstance")->willReturn($curlWrapper);
+        /** @var CurlWrapperFactory $curlWrapperFactory */
+        return $curlWrapperFactory;
     }
 
+    /**
+     * @throws Exception
+     */
     public function testStamp(){
         $pdfStampWrapper = new PDFStampWrapper("http://pdf-stamp/");
-        $pdfStampWrapper->setCurlWrapper($this->getCurlWrapper("test"));
+        $pdfStampWrapper->setCurlWrapperFactory($this->getCurlWrapperFactory("test"));
         $pdfStampData = new PDFStampData();
         $pdfStampData->identifiant_unique = "toto";
         $pdfStampData->affichage_date = "2017-09-18";
-- 
GitLab