Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ticket/11995 Fix Revert of config.remove migration #1847

Merged
merged 3 commits into from Nov 2, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions phpBB/phpbb/db/migration/tool/config.php
Expand Up @@ -130,6 +130,10 @@ public function reverse()

case 'remove':
$call = 'add';
if (sizeof($arguments) == 1)
{
$arguments[] = '';
}
break;

case 'update_if_equals':
Expand Down
91 changes: 28 additions & 63 deletions tests/dbal/migrator_tool_config_test.php
Expand Up @@ -20,102 +20,67 @@ public function setup()

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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this test removed? We're trying to make sure an exception is thrown when adding a config var that already exists.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot, exceptions are not thrown for this reason anymore.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you expect an exception, you should be using the @expectedException annotation if possible. If an exception is unexpected, phpunit should turn them into a failure automatically.

{
$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']);
}

public function test_update_if_equals()
{
$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']);
}

public function test_remove()
{
$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()
{
$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']));
}

public function test_reverse_remove()
{
$this->config->delete('foo');

$this->tool->reverse('remove', 'foo');
$this->assertEquals('', $this->config['foo']);
}

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']);
}
}