mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[feature/dic] Fix test suite for dic-powered cron
PHPBB3-10739
This commit is contained in:
parent
0a5348a137
commit
3ebe89cb7e
9 changed files with 74 additions and 33 deletions
|
@ -15,7 +15,7 @@ if (!defined('IN_PHPBB'))
|
|||
exit;
|
||||
}
|
||||
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Symfony\Component\DependencyInjection\TaggedContainerInterface;
|
||||
|
||||
/**
|
||||
* Provides cron manager with tasks
|
||||
|
@ -28,7 +28,7 @@ class phpbb_cron_task_provider implements IteratorAggregate
|
|||
{
|
||||
private $container;
|
||||
|
||||
public function __construct(Container $container)
|
||||
public function __construct(TaggedContainerInterface $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
|
|
@ -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++;
|
||||
|
|
|
@ -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++;
|
||||
|
|
|
@ -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++;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue