From bd029611404ac1b048113ec4056432d12aa72801 Mon Sep 17 00:00:00 2001
From: gloas <gloas@afi-sa.fr>
Date: Mon, 5 Mar 2018 10:37:57 +0100
Subject: [PATCH] release 7.12 : set patch level to 262 each time we use
 cosmogramme/php/upgrade_db.php

---
 cosmogramme/php/upgrade_db.php           |  2 +-
 library/Class/Migration/ScriptPatchs.php |  6 ++
 tests/library/Class/MigrationFixture.php | 88 ++++++++++++++----------
 tests/library/Class/MigrationTest.php    |  9 ++-
 4 files changed, 66 insertions(+), 39 deletions(-)

diff --git a/cosmogramme/php/upgrade_db.php b/cosmogramme/php/upgrade_db.php
index c097913038f..f0d6664b771 100644
--- a/cosmogramme/php/upgrade_db.php
+++ b/cosmogramme/php/upgrade_db.php
@@ -9,5 +9,5 @@ define('BASE_URL', $cosmo_path->getBaseUrl());
 
 
 require_once($basePath.'/../storm_init.php');
-		(new Class_Migration_ScriptPatchs())->run();
+		(new Class_Migration_ScriptPatchs())->runFrom(262);
 ?>
\ No newline at end of file
diff --git a/library/Class/Migration/ScriptPatchs.php b/library/Class/Migration/ScriptPatchs.php
index bd2ddb1bfb2..f6a279a4750 100644
--- a/library/Class/Migration/ScriptPatchs.php
+++ b/library/Class/Migration/ScriptPatchs.php
@@ -33,6 +33,12 @@ class Class_Migration_ScriptPatchs {
   }
 
 
+  public function runFrom($patch_level, $force = false) {
+    Class_CosmoVar::setValueOf('patch_level', $patch_level);
+    $this->run($force);
+  }
+
+
   public function runTo($patch_level) {
     $this->migration = (new Class_Migration_Patchs());
     $this->migration->setLastPatchNumber($patch_level)->acceptVisitor($this);
diff --git a/tests/library/Class/MigrationFixture.php b/tests/library/Class/MigrationFixture.php
index d64f8e05357..1ede80a1340 100644
--- a/tests/library/Class/MigrationFixture.php
+++ b/tests/library/Class/MigrationFixture.php
@@ -26,7 +26,7 @@ class MigrationFixture {
     Class_Migration_Patchs::setFileSystem(Storm_Test_ObjectWrapper::mock()
                                           ->whenCalled('glob')
                                           ->answers([]
-                                            ));
+                                          ));
   }
 
   public static function mockFileSystemWithSql() {
@@ -38,20 +38,34 @@ class MigrationFixture {
 
                                                      './cosmogramme/sql/patch/patch_14.php',
                                                      './cosmogramme/sql/patch/patch_12.sql',
-                                                     './cosmogramme/sql/patch/patch_5.sql'
-                                                      ]
-                                            )
+                                                     './cosmogramme/sql/patch/patch_05.sql'
+                                                     ])
+
                                           ->whenCalled('file')
-                                          ->with('./cosmogramme/sql/patch/patch_14.sql')
-                                          ->answers([ 'another working update;'])
+                                          ->with('./cosmogramme/sql/patch/patch_03.sql')
+                                          ->answers([ 'runFrom update working;'])
+
+                                          ->whenCalled('file')
+                                          ->with('./cosmogramme/sql/patch/patch_05.sql')
+                                          ->answers([ 'runFrom update working;'])
+
+                                          ->whenCalled('file')
+                                          ->with('./cosmogramme/sql/patch/patch_10.sql')
+                                          ->answers([ 'runFrom update working;'])
+
+                                          ->whenCalled('file')
+                                          ->with('./cosmogramme/sql/patch/patch_12.sql')
+                                          ->answers([ 'update working;'])
+
                                           ->whenCalled('file')
                                           ->with('./cosmogramme/sql/patch/patch_13.sql')
                                           ->answers(['update not working;',
                                                      '-- commented update;',
                                                      'another update;'])
+
                                           ->whenCalled('file')
-                                          ->with('./cosmogramme/sql/patch/patch_12.sql')
-                                          ->answers([ 'update working;'])
+                                          ->with('./cosmogramme/sql/patch/patch_14.sql')
+                                          ->answers([ 'another working update;'])
 
                                           ->whenCalled('sha1_file')
                                           ->willDo(function() { return uniqid();} )
@@ -63,14 +77,14 @@ class MigrationFixture {
 
     $mock_sql = Storm_Test_ObjectWrapper::mock();
     $mock_sql->whenCalled('execute')
-      ->with('update not working;')
-      ->willDo(function() {throw new CustomException('database error' , '666');})
-      ->whenCalled('execute')
-      ->with('update working;')
-      ->answers(true)
-      ->whenCalled('query')
-      ->with("SHOW TABLES LIKE 'patch_hash'")
-      ->answers(1);
+             ->with('update not working;')
+             ->willDo(function() {throw new CustomException('database error' , '666');})
+             ->whenCalled('execute')
+             ->with('update working;')
+             ->answers(true)
+             ->whenCalled('query')
+             ->with("SHOW TABLES LIKE 'patch_hash'")
+             ->answers(1);
 
     Zend_Registry::set('sql', $mock_sql);
     Class_Systeme_Include::setInstance($_mock_system_include);
@@ -87,7 +101,7 @@ class MigrationFixture {
                                                      './cosmogramme/sql/patch/patch_12.sql',
                                                      './cosmogramme/sql/patch/patch_15.sql',
                                                      './cosmogramme/sql/patch/patch_5.sql'
-                                                      ])
+                                                     ])
 
                                           ->whenCalled('file')
                                           ->with('./cosmogramme/sql/patch/patch_12.sql')
@@ -124,11 +138,11 @@ class MigrationFixture {
 
     $mock_sql = Storm_Test_ObjectWrapper::mock();
     $mock_sql->whenCalled('execute')
-      ->with('update working;')
-      ->answers(true)
-      ->whenCalled('query')
-      ->with("SHOW TABLES LIKE 'patch_hash'")
-      ->answers(1);
+             ->with('update working;')
+             ->answers(true)
+             ->whenCalled('query')
+             ->with("SHOW TABLES LIKE 'patch_hash'")
+             ->answers(1);
 
     Zend_Registry::set('sql', $mock_sql);
   }
@@ -140,31 +154,31 @@ class MigrationFixture {
                                           ->whenCalled('glob')
                                           ->answers(['./cosmogramme/sql/patch/patch_03.sql',
                                                      './cosmogramme/sql/patch/patch_14.sql',
-                                                      ])
+                                                     ])
                                           ->whenCalled('file')
                                           ->with('./cosmogramme/sql/patch/patch_14.sql')
                                           ->answers([ 'CREATE FUNCTION clean_spaces(str VARCHAR(255)) RETURNS VARCHAR(255) DETERMINISTIC',
-                                                      'BEGIN',
-                                                      "while instr(str, '  ') > 0 do",
-                                                      "set str := replace(str, '  ', ' ');",
-                                                      "end while;",
-                                                      "return trim(str);",
-                                                      'END'
-                                                      ])
+                                                     'BEGIN',
+                                                     "while instr(str, '  ') > 0 do",
+                                                     "set str := replace(str, '  ', ' ');",
+                                                     "end while;",
+                                                     "return trim(str);",
+                                                     'END'
+                                                     ])
 
                                           ->whenCalled('sha1_file')
                                           ->answers('bidonquiapaslatetedunchathein')
 
-      );
+    );
 
     $mock_sql = Storm_Test_ObjectWrapper::mock();
     $mock_sql->whenCalled('execute')
-      ->with("CREATE FUNCTION clean_spaces(str VARCHAR(255)) RETURNS VARCHAR(255) DETERMINISTIC BEGIN while instr(str, '  ') > 0 do set str := replace(str, '  ', ' '); end while; return trim(str); END")
-      ->answers(true)
-      ->whenCalled('query')
-      ->with("SHOW TABLES LIKE 'patch_hash'")
-      ->answers(1)
-      ->beStrict();
+             ->with("CREATE FUNCTION clean_spaces(str VARCHAR(255)) RETURNS VARCHAR(255) DETERMINISTIC BEGIN while instr(str, '  ') > 0 do set str := replace(str, '  ', ' '); end while; return trim(str); END")
+             ->answers(true)
+             ->whenCalled('query')
+             ->with("SHOW TABLES LIKE 'patch_hash'")
+             ->answers(1)
+             ->beStrict();
 
     Zend_Registry::set('sql', $mock_sql);
 
diff --git a/tests/library/Class/MigrationTest.php b/tests/library/Class/MigrationTest.php
index 73e19879e94..d2ed1de46e9 100644
--- a/tests/library/Class/MigrationTest.php
+++ b/tests/library/Class/MigrationTest.php
@@ -100,7 +100,14 @@ class Class_MigrationScriptPatchsTest extends MigrationTestCase {
   /** @test */
   public function runForcePatchShouldUpgradePatchLevelTo14() {
     (new Class_Migration_ScriptPatchs())->run(true);
-    $this->assertEquals(14,Class_CosmoVar::find('patch_level')->getValeur());
+    $this->assertEquals(14, Class_CosmoVar::find('patch_level')->getValeur());
+  }
+
+
+  /** @test */
+  public function runFromPatchShouldUpgradePatchLevelTo14() {
+    (new Class_Migration_ScriptPatchs())->runFrom(1, true);
+    $this->assertEquals(14, Class_CosmoVar::find('patch_level')->getValeur());
   }
 }
 
-- 
GitLab