mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-09 21:08:53 +00:00
Merge pull request #2551 from ptitlazy/ticket/12658
[ticket/12658] Add test for base case of commands config: * ptitlazy/ticket/12658: [ticket/12658] Rebased and fixed unit tests [ticket/12658] Fix wrong eol character [ticket/12658] Refactoring code [ticket/12658] Fix typo and coding style mistakes [ticket/12658] Add test for command config:delete [ticket/12658] Add test for command config:increment [ticket/12658] Add test for command config:get [ticket/12658] Add test for command config:set-atomic [ticket/12658] Add test for base case of command config:set
This commit is contained in:
commit
1e09fd0cee
1 changed files with 251 additions and 0 deletions
251
tests/console/config/config_test.php
Normal file
251
tests/console/config/config_test.php
Normal file
|
@ -0,0 +1,251 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
|
||||
class phpbb_console_command_config_test extends phpbb_test_case
|
||||
{
|
||||
protected $config;
|
||||
protected $command_name;
|
||||
protected $user;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->config = new \phpbb\config\config(array());
|
||||
|
||||
$this->user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime'));
|
||||
$this->user->method('lang')->will($this->returnArgument(0));
|
||||
}
|
||||
|
||||
public function test_set_dynamic()
|
||||
{
|
||||
$this->assertEmpty($this->config);
|
||||
|
||||
$command_tester = $this->get_command_tester('set');
|
||||
$command_tester->execute(array(
|
||||
'command' => $this->command_name,
|
||||
'key' => 'test_key',
|
||||
'value' => 'test_value',
|
||||
'--dynamic' => true,
|
||||
));
|
||||
|
||||
$this->assertSame($this->config['test_key'], 'test_value');
|
||||
}
|
||||
|
||||
public function test_set_no_dynamic()
|
||||
{
|
||||
$this->assertEmpty($this->config);
|
||||
|
||||
$command_tester = $this->get_command_tester('set');
|
||||
$command_tester->execute(array(
|
||||
'command' => $this->command_name,
|
||||
'key' => 'test_key',
|
||||
'value' => 'test_value',
|
||||
'--dynamic' => false,
|
||||
));
|
||||
|
||||
$this->assertSame($this->config['test_key'], 'test_value');
|
||||
}
|
||||
|
||||
public function test_set_atomic_dynamic()
|
||||
{
|
||||
$this->assertEmpty($this->config);
|
||||
|
||||
$this->config->set('test_key', 'old_value', true);
|
||||
$this->assertSame($this->config['test_key'], 'old_value');
|
||||
|
||||
$command_tester = $this->get_command_tester('set_atomic');
|
||||
$command_tester->execute(array(
|
||||
'command' => $this->command_name,
|
||||
'key' => 'test_key',
|
||||
'old' => 'old_value',
|
||||
'new' => 'new_value',
|
||||
'--dynamic' => true,
|
||||
));
|
||||
|
||||
$this->assertSame($this->config['test_key'], 'new_value');
|
||||
}
|
||||
|
||||
public function test_set_atomic_no_dynamic()
|
||||
{
|
||||
$this->assertEmpty($this->config);
|
||||
|
||||
$this->config->set('test_key', 'old_value', false);
|
||||
$this->assertSame($this->config['test_key'], 'old_value');
|
||||
|
||||
$command_tester = $this->get_command_tester('set_atomic');
|
||||
$command_tester->execute(array(
|
||||
'command' => $this->command_name,
|
||||
'key' => 'test_key',
|
||||
'old' => 'old_value',
|
||||
'new' => 'new_value',
|
||||
'--dynamic' => false,
|
||||
));
|
||||
|
||||
$this->assertSame($this->config['test_key'], 'new_value');
|
||||
}
|
||||
|
||||
public function test_set_atomic_error_dynamic()
|
||||
{
|
||||
$this->assertEmpty($this->config);
|
||||
|
||||
$this->config->set('test_key', 'wrong_value', true);
|
||||
$this->assertSame($this->config['test_key'], 'wrong_value');
|
||||
|
||||
$command_tester = $this->get_command_tester('set_atomic');
|
||||
$command_tester->execute(array(
|
||||
'command' => $this->command_name,
|
||||
'key' => 'test_key',
|
||||
'old' => 'old_value',
|
||||
'new' => 'new_value',
|
||||
'--dynamic' => true,
|
||||
));
|
||||
|
||||
$this->assertSame($this->config['test_key'], 'wrong_value');
|
||||
}
|
||||
|
||||
public function test_get_no_new_line()
|
||||
{
|
||||
$this->config->set('test_key', 'test_value', false);
|
||||
$this->assertSame($this->config['test_key'], 'test_value');
|
||||
|
||||
$command_tester = $this->get_command_tester('get');
|
||||
$command_tester->execute(array(
|
||||
'command' => $this->command_name,
|
||||
'key' => 'test_key',
|
||||
'--no-newline' => true,
|
||||
));
|
||||
|
||||
$this->assertSame($this->config['test_key'], $command_tester->getDisplay());
|
||||
}
|
||||
|
||||
public function test_get_new_line()
|
||||
{
|
||||
$this->config->set('test_key', 'test_value', false);
|
||||
$this->assertSame($this->config['test_key'], 'test_value');
|
||||
|
||||
$command_tester = $this->get_command_tester('get');
|
||||
$command_tester->execute(array(
|
||||
'command' => $this->command_name,
|
||||
'key' => 'test_key',
|
||||
'--no-newline' => false,
|
||||
));
|
||||
|
||||
$this->assertSame($this->config['test_key'] . PHP_EOL, $command_tester->getDisplay());
|
||||
}
|
||||
|
||||
public function test_get_error()
|
||||
{
|
||||
$this->config->set('test_key', 'test_value', false);
|
||||
$this->assertSame($this->config['test_key'], 'test_value');
|
||||
|
||||
$command_tester = $this->get_command_tester('get');
|
||||
$command_tester->execute(array(
|
||||
'command' => $this->command_name,
|
||||
'key' => 'wrong_key',
|
||||
'--no-newline' => false,
|
||||
));
|
||||
|
||||
$this->assertContains('CLI_CONFIG_NOT_EXISTS', $command_tester->getDisplay());
|
||||
}
|
||||
|
||||
public function test_increment_dynamic()
|
||||
{
|
||||
$this->config->set('test_key', 0, false);
|
||||
$this->assertSame($this->config['test_key'], 0);
|
||||
|
||||
$command_tester = $this->get_command_tester('increment');
|
||||
$command_tester->execute(array(
|
||||
'command' => $this->command_name,
|
||||
'key' => 'test_key',
|
||||
'increment' => 2,
|
||||
'--dynamic' => true,
|
||||
));
|
||||
|
||||
$this->assertContains('CLI_CONFIG_INCREMENT_SUCCESS', $command_tester->getDisplay());
|
||||
$this->assertSame(2, $this->config['test_key']);
|
||||
}
|
||||
|
||||
public function test_increment_no_dynamic()
|
||||
{
|
||||
$this->config->set('test_key', 0, false);
|
||||
$this->assertSame($this->config['test_key'], 0);
|
||||
|
||||
$command_tester = $this->get_command_tester('increment');
|
||||
$command_tester->execute(array(
|
||||
'command' => $this->command_name,
|
||||
'key' => 'test_key',
|
||||
'increment' => 2,
|
||||
'--dynamic' => false,
|
||||
));
|
||||
|
||||
$this->assertContains('CLI_CONFIG_INCREMENT_SUCCESS', $command_tester->getDisplay());
|
||||
$this->assertSame(2, $this->config['test_key']);
|
||||
}
|
||||
|
||||
public function test_increment_no_set()
|
||||
{
|
||||
$this->assertEmpty($this->config);
|
||||
|
||||
$command_tester = $this->get_command_tester('increment');
|
||||
$command_tester->execute(array(
|
||||
'command' => $this->command_name,
|
||||
'key' => 'test_key',
|
||||
'increment' => 2,
|
||||
'--dynamic' => true,
|
||||
));
|
||||
|
||||
$this->assertContains('CLI_CONFIG_INCREMENT_SUCCESS', $command_tester->getDisplay());
|
||||
$this->assertSame(2, $this->config['test_key']);
|
||||
}
|
||||
|
||||
public function test_delete_ok()
|
||||
{
|
||||
$this->config->set('test_key', 'test_value', false);
|
||||
$this->assertSame($this->config['test_key'], 'test_value');
|
||||
|
||||
$command_tester = $this->get_command_tester('delete');
|
||||
$command_tester->execute(array(
|
||||
'command' => $this->command_name,
|
||||
'key' => 'test_key',
|
||||
));
|
||||
|
||||
$this->assertContains('CLI_CONFIG_DELETE_SUCCESS', $command_tester->getDisplay());
|
||||
$this->assertEmpty($this->config);
|
||||
}
|
||||
|
||||
public function test_delete_error()
|
||||
{
|
||||
$this->assertEmpty($this->config);
|
||||
|
||||
$command_tester = $this->get_command_tester('delete');
|
||||
$command_tester->execute(array(
|
||||
'command' => $this->command_name,
|
||||
'key' => 'wrong_key',
|
||||
));
|
||||
|
||||
$this->assertContains('CLI_CONFIG_NOT_EXISTS', $command_tester->getDisplay());
|
||||
$this->assertEmpty($this->config);
|
||||
}
|
||||
|
||||
public function get_command_tester($class_name)
|
||||
{
|
||||
$command_complete_name = '\phpbb\console\command\config' . '\\' . $class_name;
|
||||
$application = new Application();
|
||||
$application->add(new $command_complete_name($this->user, $this->config));
|
||||
$command = $application->find('config:' . $this->command_name);
|
||||
$this->command_name = $command->getName();
|
||||
return new CommandTester($command);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue