diff options
author | Etienne Baroux <barouxe@phelma.grenoble-inp.fr> | 2014-06-03 10:42:50 +0200 |
---|---|---|
committer | Etienne Baroux <barouxe@phelma.grenoble-inp.fr> | 2014-06-03 10:42:50 +0200 |
commit | 760aa9d402aa300349b18ba785fa7ccc4b5fccf5 (patch) | |
tree | debbb9f251afdae0d70d2e504b7cf5bfb4ad974f /tests/console/cron | |
parent | 71fb956498ec882573205a0a074350372f528020 (diff) | |
download | forums-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
Diffstat (limited to 'tests/console/cron')
-rw-r--r-- | tests/console/cron/cron_list_test.php | 62 |
1 files changed, 30 insertions, 32 deletions
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 |