[ticket/12602] Changes to respect coding style and to factorize code.

PHPBB3-12602
This commit is contained in:
Etienne Baroux 2014-06-03 10:42:50 +02:00
parent 71fb956498
commit 760aa9d402
3 changed files with 45 additions and 46 deletions

View file

@ -61,20 +61,26 @@ class cron_list extends \phpbb\console\command\command
if (!empty($ready_tasks)) if (!empty($ready_tasks))
{ {
$output->writeln('<info>' . $this->user->lang('TASKS_READY') . '</info>'); $output->writeln('<info>' . $this->user->lang('TASKS_READY') . '</info>');
foreach ($ready_tasks as $task) $this->print_tasks_names($ready_tasks, $output);
{
$output->writeln($task->get_name());
} }
if (!empty($ready_tasks) && !empty($not_ready_tasks))
{
$output->writeln(''); $output->writeln('');
} }
if (!empty($not_ready_tasks)) if (!empty($not_ready_tasks))
{ {
$output->writeln('<info>' . $this->user->lang('TASKS_NOT_READY') . '</info>'); $output->writeln('<info>' . $this->user->lang('TASKS_NOT_READY') . '</info>');
foreach ($not_ready_tasks as $task) $this->print_tasks_names($not_ready_tasks, $output);
}
}
public function print_tasks_names ($tasks, $output)
{
foreach ($tasks as $task)
{ {
$output->writeln($task->get_name()); $output->writeln($task->get_name());
} }
} }
} }
}

View file

@ -128,12 +128,7 @@ class manager
*/ */
public function get_tasks() public function get_tasks()
{ {
$tasks = array(); return $this->tasks;
foreach ($this->tasks as $task)
{
$tasks[] = $task;
}
return $tasks;
} }
/** /**

View file

@ -23,6 +23,8 @@ class phpbb_console_command_cron_list_test extends phpbb_test_case
protected $command_name; protected $command_name;
protected $command_tester;
protected function setUp() protected function setUp()
{ {
$this->user = $this->getMock('\phpbb\user'); $this->user = $this->getMock('\phpbb\user');
@ -31,49 +33,26 @@ class phpbb_console_command_cron_list_test extends phpbb_test_case
public function test_no_task() public function test_no_task()
{ {
$tasks = array(); $this->initiate_test(0,0);
$this->get_cron_manager($tasks); $this->assertContains('NO_TASK', $this->command_tester->getDisplay());
$command_tester = $this->get_command_tester();
$command_tester->execute(array('command' => $this->command_name, '--no-ansi' => true));
$this->assertContains('NO_TASK', $command_tester->getDisplay());
} }
public function test_only_ready() public function test_only_ready()
{ {
$tasks = array( $this->initiate_test(2,0);
new phpbb_cron_task_simple_ready(), $this->assertContains('TASKS_READY command1 command2', preg_replace('/\s+/', ' ', trim($this->command_tester->getDisplay())));
new phpbb_cron_task_simple_ready()
);
$this->get_cron_manager($tasks);
$command_tester = $this->get_command_tester();
$command_tester->execute(array('command' => $this->command_name, '--no-ansi' => true));
$this->assertContains('TASKS_READY command1 command2', preg_replace('/\s+/', ' ', trim($command_tester->getDisplay())));
} }
public function test_only_not_ready() public function test_only_not_ready()
{ {
$tasks = array( $this->initiate_test(0,2);
new phpbb_cron_task_simple_not_ready(), $this->assertContains('TASKS_NOT_READY command1 command2', preg_replace('/\s+/', ' ', trim($this->command_tester->getDisplay())));
new phpbb_cron_task_simple_not_ready()
);
$this->get_cron_manager($tasks);
$command_tester = $this->get_command_tester();
$command_tester->execute(array('command' => $this->command_name, '--no-ansi' => true));
$this->assertContains('TASKS_NOT_READY command1 command2', preg_replace('/\s+/', ' ', trim($command_tester->getDisplay())));
} }
public function test_both_ready() public function test_both_ready()
{ {
$tasks = array( $this->initiate_test(2,2);
new phpbb_cron_task_simple_ready(), $this->assertSame('TASKS_READY command1 command2 TASKS_NOT_READY command3 command4', preg_replace('/\s+/', ' ', trim($this->command_tester->getDisplay())));
new phpbb_cron_task_simple_ready(),
new phpbb_cron_task_simple_not_ready(),
new phpbb_cron_task_simple_not_ready()
);
$this->get_cron_manager($tasks);
$command_tester = $this->get_command_tester();
$command_tester->execute(array('command' => $this->command_name, '--no-ansi' => true));
$this->assertSame('TASKS_READY command1 command2 TASKS_NOT_READY command3 command4', preg_replace('/\s+/', ' ', trim($command_tester->getDisplay())));
} }
public function get_cron_manager(array $tasks) public function get_cron_manager(array $tasks)
@ -97,4 +76,23 @@ class phpbb_console_command_cron_list_test extends phpbb_test_case
$this->command_name = $command->getName(); $this->command_name = $command->getName();
return new CommandTester($command); return new CommandTester($command);
} }
public function initiate_test ($number_ready, $number_not_ready)
{
$tasks = array();
for ($i = 0; $i < $number_ready; $i++)
{
$tasks[] = new phpbb_cron_task_simple_ready();
}
for ($i = 0; $i < $number_not_ready; $i++)
{
$tasks[] = new phpbb_cron_task_simple_not_ready();
}
$this->get_cron_manager($tasks);
$this->command_tester = $this->get_command_tester();
$this->command_tester->execute(array('command' => $this->command_name, '--no-ansi' => true));
}
} }