From 8b9f14af27e2f5b25a110226aba40df813fb330b Mon Sep 17 00:00:00 2001
From: Ghislain Loas <ghislo@sandbox.pergame.net>
Date: Thu, 28 Jan 2016 17:55:33 +0100
Subject: [PATCH] hotline #37385 fix rt comments

---
 .../Cosmogramme/Integration/PhaseAbstract.php      | 14 ++++++++++++++
 .../Integration/PhaseDeleteRecordWithoutItem.php   |  2 +-
 .../PhaseDeleteRecordWithoutItemTest.php           |  9 +--------
 3 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/library/Class/Cosmogramme/Integration/PhaseAbstract.php b/library/Class/Cosmogramme/Integration/PhaseAbstract.php
index 401a106d357..e7d2935c27d 100644
--- a/library/Class/Cosmogramme/Integration/PhaseAbstract.php
+++ b/library/Class/Cosmogramme/Integration/PhaseAbstract.php
@@ -35,6 +35,20 @@ abstract class Class_Cosmogramme_Integration_PhaseAbstract {
   }
 
 
+  public function setSqlAdapter($adapter) {
+    $this->_sql_adapter = $adapter;
+    return $this;
+  }
+
+
+  protected function getSqlAdapter() {
+    if(!$this->_sql_adapter)
+      $this->_sql_adapter = Zend_Db_Table::getDefaultAdapter();
+
+    return $this->_sql_adapter;
+  }
+
+
   protected abstract function _execute();
   protected abstract function _init($phase);
 
diff --git a/library/Class/Cosmogramme/Integration/PhaseDeleteRecordWithoutItem.php b/library/Class/Cosmogramme/Integration/PhaseDeleteRecordWithoutItem.php
index fe482ec5d6d..3b3995cf0b6 100644
--- a/library/Class/Cosmogramme/Integration/PhaseDeleteRecordWithoutItem.php
+++ b/library/Class/Cosmogramme/Integration/PhaseDeleteRecordWithoutItem.php
@@ -30,7 +30,7 @@ class Class_Cosmogramme_Integration_PhaseDeleteRecordWithoutItem extends Class_C
     $page_size = 100;
     $page = 0;
 
-    while($records_ids = Zend_Registry::get('sql')->fetchAll('SELECT notices.id_notice FROM notices WHERE notices.id_notice NOT IN (SELECT exemplaires.id_notice FROM exemplaires) LIMIT ' . $page . ', ' . $page_size)) {
+    while($records_ids = $this->getSqlAdapter()->fetchAll('SELECT notices.id_notice FROM notices WHERE notices.id_notice NOT IN (SELECT exemplaires.id_notice FROM exemplaires) LIMIT ' . $page . ', ' . $page_size)) {
 
       if ($this->isTimeOut())
         return $this->_resetDbConnection()
diff --git a/tests/library/Class/Cosmogramme/Integration/PhaseDeleteRecordWithoutItemTest.php b/tests/library/Class/Cosmogramme/Integration/PhaseDeleteRecordWithoutItemTest.php
index 5f42eac3861..e31c6ddc872 100644
--- a/tests/library/Class/Cosmogramme/Integration/PhaseDeleteRecordWithoutItemTest.php
+++ b/tests/library/Class/Cosmogramme/Integration/PhaseDeleteRecordWithoutItemTest.php
@@ -27,6 +27,7 @@ abstract class PhaseDeleteRecordWithoutItemTestCase extends Class_Cosmogramme_In
     parent::setUp();
     $this->_phase = $this->_buildPhase('DeleteRecordWithoutItem')
                          ->setMemoryCleaner(function() {})
+                         ->setSqlAdapter($this->_mock_sql)
                          ->run();
     Class_Notice::clearCache();
     Class_Exemplaire::clearCache();
@@ -63,21 +64,14 @@ abstract class PhaseDeleteRecordWithoutItemTestCase extends Class_Cosmogramme_In
 
 
 
-
 class PhaseDeleteRecordWithoutItemSimpleTest extends PhaseDeleteRecordWithoutItemTestCase {
 
-  public function setUp() {
-    parent::setup();
-  }
-
-
   protected function _prepareFixtures() {
     parent::_prepareFixtures();
     $this->fixture('Class_Notice', ['id' => 34]);
     $this->fixture('Class_Notice', ['id' => 35]);
 
     $this->_mock_sql = Storm_Test_ObjectWrapper::mock();
-    Zend_Registry::set('sql', $this->_mock_sql);
 
     $this->_mock_sql
       ->whenCalled('fetchAll')
@@ -112,7 +106,6 @@ class PhaseDeleteRecordWithoutItemNothingToDeleteTest extends PhaseDeleteRecordW
   protected function _prepareFixtures() {
     parent::_prepareFixtures();
     $this->_mock_sql = Storm_Test_ObjectWrapper::mock();
-    Zend_Registry::set('sql', $this->_mock_sql);
 
     $this->_mock_sql
       ->whenCalled('fetchAll')
-- 
GitLab