From a175b091b9066478900d4a1a92c3e67f33cd9b33 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 2 Nov 2013 18:12:50 +0100 Subject: [PATCH 1/3] [ticket/11995] Add unit test for reverting config.remove PHPBB3-11995 --- tests/dbal/migrator_tool_config_test.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/dbal/migrator_tool_config_test.php b/tests/dbal/migrator_tool_config_test.php index a8d8966839..d007e36da1 100644 --- a/tests/dbal/migrator_tool_config_test.php +++ b/tests/dbal/migrator_tool_config_test.php @@ -94,6 +94,7 @@ class phpbb_dbal_migrator_tool_config_test extends phpbb_test_case public function test_reverse() { + // add $this->config->set('foo', 'bar'); try @@ -106,6 +107,21 @@ class phpbb_dbal_migrator_tool_config_test extends phpbb_test_case } $this->assertFalse(isset($this->config['foo'])); + // remove + $this->config->delete('foo'); + + try + { + $this->tool->reverse('remove', 'foo'); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertTrue(isset($this->config['foo'])); + $this->assertEquals('', $this->config['foo']); + + // update_if_equals $this->config->set('foo', 'bar'); try From 414a4d587e0d19795cc621c4eb482b1c90e22251 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 2 Nov 2013 18:13:11 +0100 Subject: [PATCH 2/3] [ticket/11995] Fix Revert of config.remove PHPBB3-11995 --- phpBB/phpbb/db/migration/tool/config.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/phpBB/phpbb/db/migration/tool/config.php b/phpBB/phpbb/db/migration/tool/config.php index f2149dc59a..36a1931f4e 100644 --- a/phpBB/phpbb/db/migration/tool/config.php +++ b/phpBB/phpbb/db/migration/tool/config.php @@ -130,6 +130,10 @@ class config implements \phpbb\db\migration\tool\tool_interface case 'remove': $call = 'add'; + if (sizeof($arguments) == 1) + { + $arguments[] = ''; + } break; case 'update_if_equals': From e8a3028ea6505942f6f192105b75dabc177dae44 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 2 Nov 2013 19:26:45 +0100 Subject: [PATCH 3/3] [ticket/11995] Remove exceptions and split reverse into different tests PHPBB3-11995 --- tests/dbal/migrator_tool_config_test.php | 99 ++++++------------------ 1 file changed, 24 insertions(+), 75 deletions(-) diff --git a/tests/dbal/migrator_tool_config_test.php b/tests/dbal/migrator_tool_config_test.php index d007e36da1..807399385c 100644 --- a/tests/dbal/migrator_tool_config_test.php +++ b/tests/dbal/migrator_tool_config_test.php @@ -20,35 +20,24 @@ class phpbb_dbal_migrator_tool_config_test extends phpbb_test_case public function test_add() { - try - { - $this->tool->add('foo', 'bar'); - } - catch (Exception $e) - { - $this->fail($e); - } + $this->tool->add('foo', 'bar'); + $this->assertEquals('bar', $this->config['foo']); + } + + public function test_add_twice() + { + $this->tool->add('foo', 'bar'); $this->assertEquals('bar', $this->config['foo']); - try - { - $this->tool->add('foo', 'bar'); - $this->fail('Exception not thrown'); - } - catch (Exception $e) {} + $this->tool->add('foo', 'bar2'); + $this->assertEquals('bar', $this->config['foo']); } public function test_update() { $this->config->set('foo', 'bar'); - try - { - $this->tool->update('foo', 'bar2'); - } - catch (Exception $e) - { - $this->fail($e); - } + + $this->tool->update('foo', 'bar2'); $this->assertEquals('bar2', $this->config['foo']); } @@ -56,24 +45,10 @@ class phpbb_dbal_migrator_tool_config_test extends phpbb_test_case { $this->config->set('foo', 'bar'); - try - { - $this->tool->update_if_equals('', 'foo', 'bar2'); - } - catch (Exception $e) - { - $this->fail($e); - } + $this->tool->update_if_equals('', 'foo', 'bar2'); $this->assertEquals('bar', $this->config['foo']); - try - { - $this->tool->update_if_equals('bar', 'foo', 'bar2'); - } - catch (Exception $e) - { - $this->fail($e); - } + $this->tool->update_if_equals('bar', 'foo', 'bar2'); $this->assertEquals('bar2', $this->config['foo']); } @@ -81,57 +56,31 @@ class phpbb_dbal_migrator_tool_config_test extends phpbb_test_case { $this->config->set('foo', 'bar'); - try - { - $this->tool->remove('foo'); - } - catch (Exception $e) - { - $this->fail($e); - } + $this->tool->remove('foo'); $this->assertFalse(isset($this->config['foo'])); } - public function test_reverse() + public function test_reverse_add() { - // add $this->config->set('foo', 'bar'); - try - { - $this->tool->reverse('add', 'foo'); - } - catch (Exception $e) - { - $this->fail($e); - } + $this->tool->reverse('add', 'foo'); $this->assertFalse(isset($this->config['foo'])); + } - // remove + public function test_reverse_remove() + { $this->config->delete('foo'); - try - { - $this->tool->reverse('remove', 'foo'); - } - catch (Exception $e) - { - $this->fail($e); - } - $this->assertTrue(isset($this->config['foo'])); + $this->tool->reverse('remove', 'foo'); $this->assertEquals('', $this->config['foo']); + } - // update_if_equals + public function test_reverse_update_if_equals() + { $this->config->set('foo', 'bar'); - try - { - $this->tool->reverse('update_if_equals', 'test', 'foo', 'bar'); - } - catch (Exception $e) - { - $this->fail($e); - } + $this->tool->reverse('update_if_equals', 'test', 'foo', 'bar'); $this->assertEquals('test', $this->config['foo']); } }