aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEtienne Baroux <barouxe@phelma.grenoble-inp.fr>2014-06-03 10:42:50 +0200
committerEtienne Baroux <barouxe@phelma.grenoble-inp.fr>2014-06-03 10:42:50 +0200
commit760aa9d402aa300349b18ba785fa7ccc4b5fccf5 (patch)
treedebbb9f251afdae0d70d2e504b7cf5bfb4ad974f
parent71fb956498ec882573205a0a074350372f528020 (diff)
downloadforums-760aa9d402aa300349b18ba785fa7ccc4b5fccf5.tar
forums-760aa9d402aa300349b18ba785fa7ccc4b5fccf5.tar.gz
forums-760aa9d402aa300349b18ba785fa7ccc4b5fccf5.tar.bz2
forums-760aa9d402aa300349b18ba785fa7ccc4b5fccf5.tar.xz
forums-760aa9d402aa300349b18ba785fa7ccc4b5fccf5.zip
[ticket/12602] Changes to respect coding style and to factorize code.
PHPBB3-12602
-rw-r--r--phpBB/phpbb/console/command/cron/cron_list.php22
-rw-r--r--phpBB/phpbb/cron/manager.php7
-rw-r--r--tests/console/cron/cron_list_test.php62
3 files changed, 45 insertions, 46 deletions
diff --git a/phpBB/phpbb/console/command/cron/cron_list.php b/phpBB/phpbb/console/command/cron/cron_list.php
index beedc3c932..f95cb6fb03 100644
--- a/phpBB/phpbb/console/command/cron/cron_list.php
+++ b/phpBB/phpbb/console/command/cron/cron_list.php
@@ -61,20 +61,26 @@ class cron_list extends \phpbb\console\command\command
if (!empty($ready_tasks))
{
$output->writeln('<info>' . $this->user->lang('TASKS_READY') . '</info>');
- foreach ($ready_tasks as $task)
- {
- $output->writeln($task->get_name());
- }
+ $this->print_tasks_names($ready_tasks, $output);
+ }
+
+ if (!empty($ready_tasks) && !empty($not_ready_tasks))
+ {
$output->writeln('');
}
if (!empty($not_ready_tasks))
{
$output->writeln('<info>' . $this->user->lang('TASKS_NOT_READY') . '</info>');
- foreach ($not_ready_tasks as $task)
- {
- $output->writeln($task->get_name());
- }
+ $this->print_tasks_names($not_ready_tasks, $output);
+ }
+ }
+
+ public function print_tasks_names ($tasks, $output)
+ {
+ foreach ($tasks as $task)
+ {
+ $output->writeln($task->get_name());
}
}
}
diff --git a/phpBB/phpbb/cron/manager.php b/phpBB/phpbb/cron/manager.php
index 77dfcff471..f04f063228 100644
--- a/phpBB/phpbb/cron/manager.php
+++ b/phpBB/phpbb/cron/manager.php
@@ -128,12 +128,7 @@ class manager
*/
public function get_tasks()
{
- $tasks = array();
- foreach ($this->tasks as $task)
- {
- $tasks[] = $task;
- }
- return $tasks;
+ return $this->tasks;
}
/**
diff --git a/tests/console/cron/cron_list_test.php b/tests/console/cron/cron_list_test.php
index aabd3e388a..dd4a33ee62 100644
--- a/tests/console/cron/cron_list_test.php
+++ b/tests/console/cron/cron_list_test.php
@@ -23,6 +23,8 @@ class phpbb_console_command_cron_list_test extends phpbb_test_case
protected $command_name;
+ protected $command_tester;
+
protected function setUp()
{
$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()
{
- $tasks = array();
- $this->get_cron_manager($tasks);
- $command_tester = $this->get_command_tester();
- $command_tester->execute(array('command' => $this->command_name, '--no-ansi' => true));
- $this->assertContains('NO_TASK', $command_tester->getDisplay());
+ $this->initiate_test(0,0);
+ $this->assertContains('NO_TASK', $this->command_tester->getDisplay());
}
public function test_only_ready()
{
- $tasks = array(
- new phpbb_cron_task_simple_ready(),
- 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())));
+ $this->initiate_test(2,0);
+ $this->assertContains('TASKS_READY command1 command2', preg_replace('/\s+/', ' ', trim($this->command_tester->getDisplay())));
}
public function test_only_not_ready()
{
- $tasks = array(
- 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->assertContains('TASKS_NOT_READY command1 command2', preg_replace('/\s+/', ' ', trim($command_tester->getDisplay())));
+ $this->initiate_test(0,2);
+ $this->assertContains('TASKS_NOT_READY command1 command2', preg_replace('/\s+/', ' ', trim($this->command_tester->getDisplay())));
}
public function test_both_ready()
{
- $tasks = array(
- new phpbb_cron_task_simple_ready(),
- 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())));
+ $this->initiate_test(2,2);
+ $this->assertSame('TASKS_READY command1 command2 TASKS_NOT_READY command3 command4', preg_replace('/\s+/', ' ', trim($this->command_tester->getDisplay())));
}
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();
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));
+ }
+} \ No newline at end of file