diff options
author | Igor Wiedler <igor@wiedler.ch> | 2012-04-09 15:05:28 +0200 |
---|---|---|
committer | Igor Wiedler <igor@wiedler.ch> | 2012-04-09 15:05:28 +0200 |
commit | 3ebe89cb7eff57c3ffdbe0b7dcd9cdc35b48d26b (patch) | |
tree | 9a5c38eb1f18d2d3219b3fa0a4cb4bd9fc854dd4 /tests/cron | |
parent | 0a5348a1376fafb487884086a70069bea8c5640b (diff) | |
download | forums-3ebe89cb7eff57c3ffdbe0b7dcd9cdc35b48d26b.tar forums-3ebe89cb7eff57c3ffdbe0b7dcd9cdc35b48d26b.tar.gz forums-3ebe89cb7eff57c3ffdbe0b7dcd9cdc35b48d26b.tar.bz2 forums-3ebe89cb7eff57c3ffdbe0b7dcd9cdc35b48d26b.tar.xz forums-3ebe89cb7eff57c3ffdbe0b7dcd9cdc35b48d26b.zip |
[feature/dic] Fix test suite for dic-powered cron
PHPBB3-10739
Diffstat (limited to 'tests/cron')
-rw-r--r-- | tests/cron/ext/testext/cron/dummy_task.php | 5 | ||||
-rw-r--r-- | tests/cron/includes/cron/task/core/dummy_task.php | 5 | ||||
-rw-r--r-- | tests/cron/includes/cron/task/core/second_dummy_task.php | 5 | ||||
-rw-r--r-- | tests/cron/manager_test.php | 32 | ||||
-rw-r--r-- | tests/cron/task_provider_test.php | 41 | ||||
-rw-r--r-- | tests/cron/tasks/simple_not_runnable.php | 5 | ||||
-rw-r--r-- | tests/cron/tasks/simple_ready.php | 5 | ||||
-rw-r--r-- | tests/cron/tasks/simple_should_not_run.php | 5 |
8 files changed, 72 insertions, 31 deletions
diff --git a/tests/cron/ext/testext/cron/dummy_task.php b/tests/cron/ext/testext/cron/dummy_task.php index 996f5b39cf..a31806c1b1 100644 --- a/tests/cron/ext/testext/cron/dummy_task.php +++ b/tests/cron/ext/testext/cron/dummy_task.php @@ -11,6 +11,11 @@ class phpbb_ext_testext_cron_dummy_task extends phpbb_cron_task_base { public static $was_run = 0; + public function get_name() + { + return get_class($this); + } + public function run() { self::$was_run++; diff --git a/tests/cron/includes/cron/task/core/dummy_task.php b/tests/cron/includes/cron/task/core/dummy_task.php index 6e2e2db636..ce3e91a9ba 100644 --- a/tests/cron/includes/cron/task/core/dummy_task.php +++ b/tests/cron/includes/cron/task/core/dummy_task.php @@ -11,6 +11,11 @@ class phpbb_cron_task_core_dummy_task extends phpbb_cron_task_base { public static $was_run = 0; + public function get_name() + { + return get_class($this); + } + public function run() { self::$was_run++; diff --git a/tests/cron/includes/cron/task/core/second_dummy_task.php b/tests/cron/includes/cron/task/core/second_dummy_task.php index 8cd0bddfc0..76a55588f9 100644 --- a/tests/cron/includes/cron/task/core/second_dummy_task.php +++ b/tests/cron/includes/cron/task/core/second_dummy_task.php @@ -11,6 +11,11 @@ class phpbb_cron_task_core_second_dummy_task extends phpbb_cron_task_base { public static $was_run = 0; + public function get_name() + { + return get_class($this); + } + public function run() { self::$was_run++; diff --git a/tests/cron/manager_test.php b/tests/cron/manager_test.php index f433fc9a9b..8ed33b06e2 100644 --- a/tests/cron/manager_test.php +++ b/tests/cron/manager_test.php @@ -19,10 +19,10 @@ class phpbb_cron_manager_test extends PHPUnit_Framework_TestCase { public function setUp() { - $this->manager = new phpbb_cron_manager(array( - 'phpbb_cron_task_core_dummy_task', - 'phpbb_cron_task_core_second_dummy_task', - 'phpbb_ext_testext_cron_dummy_task', + $this->manager = $this->create_cron_manager(array( + new phpbb_cron_task_core_dummy_task(), + new phpbb_cron_task_core_second_dummy_task(), + new phpbb_ext_testext_cron_dummy_task(), )); $this->task_name = 'phpbb_cron_task_core_dummy_task'; } @@ -34,13 +34,6 @@ class phpbb_cron_manager_test extends PHPUnit_Framework_TestCase $this->assertEquals($this->task_name, $task->get_name()); } - public function test_manager_instantiates_task_by_name() - { - $task = $this->manager->instantiate_task($this->task_name, array()); - $this->assertInstanceOf('phpbb_cron_task_wrapper', $task); - $this->assertEquals($this->task_name, $task->get_name()); - } - public function test_manager_finds_all_ready_tasks() { $tasks = $this->manager->find_all_ready_tasks(); @@ -55,10 +48,10 @@ class phpbb_cron_manager_test extends PHPUnit_Framework_TestCase public function test_manager_finds_only_ready_tasks() { - $manager = new phpbb_cron_manager(array( - 'phpbb_cron_task_core_simple_ready', - 'phpbb_cron_task_core_simple_not_runnable', - 'phpbb_cron_task_core_simple_should_not_run', + $manager = $this->create_cron_manager(array( + new phpbb_cron_task_core_simple_ready(), + new phpbb_cron_task_core_simple_not_runnable(), + new phpbb_cron_task_core_simple_should_not_run(), )); $tasks = $manager->find_all_ready_tasks(); $task_names = $this->tasks_to_names($tasks); @@ -70,8 +63,15 @@ class phpbb_cron_manager_test extends PHPUnit_Framework_TestCase $names = array(); foreach ($tasks as $task) { - $names[] = get_class($task->task); + $names[] = $task->get_name(); } return $names; } + + private function create_cron_manager($tasks) + { + global $phpbb_root_path, $phpEx; + + return new phpbb_cron_manager($tasks, $phpbb_root_path, $phpEx); + } } diff --git a/tests/cron/task_provider_test.php b/tests/cron/task_provider_test.php index 4547c61a55..4458d811a5 100644 --- a/tests/cron/task_provider_test.php +++ b/tests/cron/task_provider_test.php @@ -7,37 +7,48 @@ * */ -require_once dirname(__FILE__) . '/../mock/extension_manager.php'; +require_once dirname(__FILE__) . '/includes/cron/task/core/dummy_task.php'; +require_once dirname(__FILE__) . '/includes/cron/task/core/second_dummy_task.php'; +require_once dirname(__FILE__) . '/ext/testext/cron/dummy_task.php'; class phpbb_cron_task_provider_test extends PHPUnit_Framework_TestCase { public function setUp() { - $this->extension_manager = new phpbb_mock_extension_manager( - dirname(__FILE__) . '/', - array( - 'testext' => array( - 'ext_name' => 'testext', - 'ext_active' => true, - 'ext_path' => 'ext/testext/' - ), - )); - $this->provider = new phpbb_cron_task_provider($this->extension_manager); + $this->tasks = array( + 'phpbb_cron_task_core_dummy_task', + 'phpbb_cron_task_core_second_dummy_task', + 'phpbb_ext_testext_cron_dummy_task', + ); + + $container = $this->getMock('Symfony\Component\DependencyInjection\TaggedContainerInterface'); + $container + ->expects($this->once()) + ->method('findTaggedServiceIds') + ->will($this->returnValue(array_flip($this->tasks))); + $container + ->expects($this->any()) + ->method('get') + ->will($this->returnCallback(function ($name) { + return new $name; + })); + + $this->provider = new phpbb_cron_task_provider($container); } public function test_manager_finds_shipped_tasks() { - $tasks = array(); + $task_names = array(); foreach ($this->provider as $task) { - $tasks[] = $task; + $task_names[] = $task->get_name(); } - sort($tasks); + sort($task_names); $this->assertEquals(array( 'phpbb_cron_task_core_dummy_task', 'phpbb_cron_task_core_second_dummy_task', 'phpbb_ext_testext_cron_dummy_task', - ), $tasks); + ), $task_names); } } diff --git a/tests/cron/tasks/simple_not_runnable.php b/tests/cron/tasks/simple_not_runnable.php index 837f28f1c0..56d484eacd 100644 --- a/tests/cron/tasks/simple_not_runnable.php +++ b/tests/cron/tasks/simple_not_runnable.php @@ -2,6 +2,11 @@ class phpbb_cron_task_core_simple_not_runnable extends phpbb_cron_task_base { + public function get_name() + { + return get_class($this); + } + public function run() { } diff --git a/tests/cron/tasks/simple_ready.php b/tests/cron/tasks/simple_ready.php index de5f10e491..8aa0507406 100644 --- a/tests/cron/tasks/simple_ready.php +++ b/tests/cron/tasks/simple_ready.php @@ -2,6 +2,11 @@ class phpbb_cron_task_core_simple_ready extends phpbb_cron_task_base { + public function get_name() + { + return get_class($this); + } + public function run() { } diff --git a/tests/cron/tasks/simple_should_not_run.php b/tests/cron/tasks/simple_should_not_run.php index c2a41616f6..58f6df2616 100644 --- a/tests/cron/tasks/simple_should_not_run.php +++ b/tests/cron/tasks/simple_should_not_run.php @@ -2,6 +2,11 @@ class phpbb_cron_task_core_simple_should_not_run extends phpbb_cron_task_base { + public function get_name() + { + return get_class($this); + } + public function run() { } |