Commit bd029611 authored by Ghislain Loas's avatar Ghislain Loas

release 7.12 : set patch level to 262 each time we use cosmogramme/php/upgrade_db.php

parent b06c66f4
......@@ -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
......@@ -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);
......
......@@ -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);
......
......@@ -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());
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment