Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iMattPro committed May 31, 2021
1 parent aa758fc commit b83faa1
Show file tree
Hide file tree
Showing 19 changed files with 75 additions and 96 deletions.
9 changes: 5 additions & 4 deletions tests/acp/module_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace vse\abbc3\acp;

use Symfony\Component\DependencyInjection\ContainerInterface;
use PHPUnit\Framework\MockObject\MockObject;

require_once __DIR__ . '/../../../../../includes/functions_acp.php';

Expand All @@ -19,10 +20,10 @@ class module_test extends \phpbb_database_test_case
/** @var bool A return value for check_form_key() */
public static $valid_form = false;

/** @var \Symfony\Component\DependencyInjection\ContainerInterface|\PHPUnit_Framework_MockObject_MockObject */
/** @var ContainerInterface|MockObject */
protected $container;

/** @var \phpbb\cache\driver\driver_interface|\PHPUnit_Framework_MockObject_MockObject */
/** @var \phpbb\cache\driver\driver_interface|MockObject */
protected $cache;

/** @var \phpbb\config\config */
Expand All @@ -34,10 +35,10 @@ class module_test extends \phpbb_database_test_case
/** @var \phpbb\language\language */
protected $lang;

/** @var \phpbb\request\request|\PHPUnit_Framework_MockObject_MockObject */
/** @var \phpbb\request\request|MockObject */
protected $request;

/** @var \phpbb\template\template|\PHPUnit_Framework_MockObject_MockObject */
/** @var \phpbb\template\template|MockObject */
protected $template;

protected static function setup_extensions()
Expand Down
6 changes: 3 additions & 3 deletions tests/controller/wizard_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ class wizard_test extends \phpbb_test_case
/** @var \vse\abbc3\controller\wizard */
protected $controller;

/** @var \phpbb\request\request|\PHPUnit_Framework_MockObject_MockObject */
/** @var \phpbb\request\request|\PHPUnit\Framework\MockObject\MockObject */
protected $request;

/** @var \phpbb\template\template|\PHPUnit_Framework_MockObject_MockObject */
/** @var \phpbb\template\template|\PHPUnit\Framework\MockObject\MockObject */
protected $template;

/** @var \phpbb\textformatter\s9e\factory $factory */
Expand All @@ -38,7 +38,7 @@ protected function setUp(): void
->disableOriginalConstructor()
->getMock();

/** @var $controller_helper \phpbb\controller\helper|\PHPUnit_Framework_MockObject_MockObject */
/** @var $controller_helper \phpbb\controller\helper|\PHPUnit\Framework\MockObject\MockObject */
$controller_helper = $this->getMockBuilder('\phpbb\controller\helper')
->disableOriginalConstructor()
->getMock();
Expand Down
13 changes: 8 additions & 5 deletions tests/core/acp_base.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
namespace vse\abbc3\tests\core;

use phpbb\config\config;
use phpbb\db\driver\driver_interface as db;
use phpbb\filesystem\filesystem;
use phpbb\group\helper;
use phpbb\language\language;
use phpbb\language\language_file_loader;
use phpbb\path_helper;
use phpbb\request\request;
use phpbb\symfony_request;
use phpbb\user;
use PHPUnit\Framework\MockObject\MockObject;
use vse\abbc3\core\acp_manager;

class acp_base extends \phpbb_database_test_case
Expand All @@ -27,19 +30,19 @@ protected static function setup_extensions()
return ['vse/abbc3'];
}

/** @var \phpbb\db\driver\driver_interface */
/** @var db */
protected $db;

/** @var \phpbb\group\helper */
/** @var helper */
protected $group_helper;

/** @var \phpbb\language\language */
/** @var language */
protected $lang;

/** @var \phpbb\request\request|\PHPUnit_Framework_MockObject_MockObject */
/** @var request|MockObject */
protected $request;

/** @var \phpbb\user */
/** @var user */
protected $user;

public function getDataSet()
Expand Down
4 changes: 2 additions & 2 deletions tests/core/bbcodes_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ public function allowed_bbcodes_data()
*/
public function test_allow_custom_bbcodes($user_id, $data, $disable)
{
/** @var \s9e\TextFormatter\Parser|\PHPUnit_Framework_MockObject_MockObject $parser */
/** @var \s9e\TextFormatter\Parser|\PHPUnit\Framework\MockObject\MockObject $parser */
$parser = $this->getMockBuilder('\s9e\TextFormatter\Parser')
->disableOriginalConstructor()
->getMock();
$parser->registeredVars['abbc3.bbcode_groups'] = [
$data['bbcode_tag'] => $data['bbcode_group'],
];

/** @var \phpbb\textformatter\s9e\parser|\PHPUnit_Framework_MockObject_MockObject $service */
/** @var \phpbb\textformatter\s9e\parser|\PHPUnit\Framework\MockObject\MockObject $service */
$service = $this->getMockBuilder('\phpbb\textformatter\s9e\parser')
->disableOriginalConstructor()
->getMock();
Expand Down
2 changes: 1 addition & 1 deletion tests/core/faq_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected static function setup_extensions()
/** @var \phpbb\language\language */
protected $language;

/** @var \phpbb\template\template|\PHPUnit_Framework_MockObject_MockObject */
/** @var \phpbb\template\template|\PHPUnit\Framework\MockObject\MockObject */
protected $template;

/** @var \vse\abbc3\core\bbcodes_help */
Expand Down
9 changes: 3 additions & 6 deletions tests/event/acp_bbcodes_custom_sorting_buttons_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,12 @@ public function test_acp_bbcodes_custom_sorting_buttons($row, $bbcodes_array, $e
{
$this->set_listener();

$dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();
$dispatcher = new \phpbb\event\dispatcher();
$dispatcher->addListener('core.acp_bbcodes_display_bbcodes', [$this->listener, 'acp_bbcodes_custom_sorting_buttons']);

$event_data = ['row', 'bbcodes_array'];
$event = new \phpbb\event\data(compact($event_data));
$dispatcher->dispatch('core.acp_bbcodes_display_bbcodes', $event);

$event_data_returned = $event->get_data_filtered($event_data);
$bbcodes_array = $event_data_returned['bbcodes_array'];
$event_data_returned =$dispatcher->trigger_event('core.acp_bbcodes_display_bbcodes', compact($event_data));
extract($event_data_returned, EXTR_OVERWRITE);

self::assertEquals($expected, $bbcodes_array);
}
Expand Down
15 changes: 5 additions & 10 deletions tests/event/acp_bbcodes_custom_sorting_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,12 @@ public function test_acp_bbcodes_custom_sorting($template_data, $sql_ary, $u_act
{
$this->set_listener();

$dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();
$dispatcher = new \phpbb\event\dispatcher();
$dispatcher->addListener('core.acp_bbcodes_display_form', [$this->listener, 'acp_bbcodes_custom_sorting']);

$event_data = ['template_data', 'sql_ary', 'u_action'];
$event = new \phpbb\event\data(compact($event_data));
$dispatcher->dispatch('core.acp_bbcodes_display_form', $event);

$event_data_returned = $event->get_data_filtered($event_data);
$template_data = $event_data_returned['template_data'];
$sql_ary = $event_data_returned['sql_ary'];
$event_data_returned = $dispatcher->trigger_event('core.acp_bbcodes_display_form', compact($event_data));
extract($event_data_returned, EXTR_OVERWRITE);

self::assertEquals($expected_template_data, $template_data);
self::assertEquals($expected_sql_ary, $sql_ary);
Expand Down Expand Up @@ -107,11 +103,10 @@ public function test_acp_bbcodes_custom_sorting_move($action, $method, $call)
$this->acp_manager->expects(($call ? self::once() : self::never()))
->method($method);

$dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();
$dispatcher = new \phpbb\event\dispatcher();
$dispatcher->addListener('core.acp_bbcodes_display_form', [$this->listener, 'acp_bbcodes_custom_sorting']);

$event_data = ['action'];
$event = new \phpbb\event\data(compact($event_data));
$dispatcher->dispatch('core.acp_bbcodes_display_form', $event);
$dispatcher->trigger_event('core.acp_bbcodes_display_form', compact($event_data));
}
}
9 changes: 3 additions & 6 deletions tests/event/acp_bbcodes_group_select_box_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,12 @@ public function test_acp_bbcodes_group_select_box($bbcode_id, $action, $bbcode_g
->with($bbcode_group)
->willReturn($group_opts);

$dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();
$dispatcher = new \phpbb\event\dispatcher();
$dispatcher->addListener('core.acp_bbcodes_edit_add', [$this->listener, 'acp_bbcodes_group_select_box']);

$event_data = ['action', 'bbcode_id', 'tpl_ary'];
$event = new \phpbb\event\data(compact($event_data));
$dispatcher->dispatch('core.acp_bbcodes_edit_add', $event);

$event_data_returned = $event->get_data_filtered($event_data);
$tpl_ary = $event_data_returned['tpl_ary'];
$event_data_returned = $dispatcher->trigger_event('core.acp_bbcodes_edit_add', compact($event_data));
extract($event_data_returned, EXTR_OVERWRITE);

self::assertEquals($expected, $tpl_ary);
}
Expand Down
10 changes: 3 additions & 7 deletions tests/event/acp_bbcodes_modify_create_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,12 @@ public function test_acp_bbcodes_modify_create($max_order, $bbcode_group, $actio
->method('get_bbcode_group_form_data')
->willReturn($bbcode_group);

$dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();
$dispatcher = new \phpbb\event\dispatcher();
$dispatcher->addListener('core.acp_bbcodes_modify_create', [$this->listener, 'acp_bbcodes_modify_create']);

$event_data = ['action', 'sql_ary', 'hidden_fields'];
$event = new \phpbb\event\data(compact($event_data));
$dispatcher->dispatch('core.acp_bbcodes_modify_create', $event);

$event_data_returned = $event->get_data_filtered($event_data);
$hidden_fields = $event_data_returned['hidden_fields'];
$sql_ary = $event_data_returned['sql_ary'];
$event_data_returned = $dispatcher->trigger_event('core.acp_bbcodes_modify_create', compact($event_data));
extract($event_data_returned, EXTR_OVERWRITE);

self::assertEquals($expected_sql_ary, $sql_ary);
self::assertEquals($expected_hidden_fields, $hidden_fields);
Expand Down
2 changes: 1 addition & 1 deletion tests/event/acp_listener_base.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class acp_listener_base extends \phpbb_test_case
/** @var \vse\abbc3\event\listener */
protected $listener;

/** @var \vse\abbc3\core\acp_manager|\PHPUnit_Framework_MockObject_MockObject */
/** @var \vse\abbc3\core\acp_manager|\PHPUnit\Framework\MockObject\MockObject */
protected $acp_manager;

/**
Expand Down
5 changes: 2 additions & 3 deletions tests/event/acp_s9e_store_bbcode_groups_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@ public function test_s9e_store_bbcode_groups()

$configurator = new \s9e\TextFormatter\Configurator();

$dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();
$dispatcher = new \phpbb\event\dispatcher();
$dispatcher->addListener('core.text_formatter_s9e_configure_after', [$this->listener, 's9e_store_bbcode_groups']);

$event_data = ['configurator'];
$event = new \phpbb\event\data(compact($event_data));
$dispatcher->dispatch('core.text_formatter_s9e_configure_after', $event);
$dispatcher->trigger_event('core.text_formatter_s9e_configure_after', compact($event_data));

self::assertSame($test_data, $configurator->registeredVars['abbc3.bbcode_groups']);
}
Expand Down
5 changes: 2 additions & 3 deletions tests/event/bbcode_faq_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,10 @@ public function test_add_bbcode_faq($block_name, $expected)
$this->bbcodes_help->expects(($expected ? self::once() : self::never()))
->method('faq');

$dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();
$dispatcher = new \phpbb\event\dispatcher();
$dispatcher->addListener('core.help_manager_add_block_after', [$this->listener, 'add_bbcode_faq']);

$event_data = ['block_name'];
$event = new \phpbb\event\data(compact($event_data));
$dispatcher->dispatch('core.help_manager_add_block_after', $event);
$dispatcher->trigger_event('core.help_manager_add_block_after', compact($event_data));
}
}
9 changes: 3 additions & 6 deletions tests/event/custom_bbcode_modify_sql_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,13 @@ public function test_custom_bbcode_modify_sql($sql_ary, $expected)
{
$this->set_listener();

$dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();
$dispatcher = new \phpbb\event\dispatcher();
$dispatcher->addListener('core.display_custom_bbcodes_modify_sql', [$this->listener, 'custom_bbcode_modify_sql']);

$num_predefined_bbcodes = 22;
$event_data = ['sql_ary', 'num_predefined_bbcodes'];
$event = new \phpbb\event\data(compact($event_data));
$dispatcher->dispatch('core.display_custom_bbcodes_modify_sql', $event);

$sql_ary = $event->get_data_filtered($event_data);
$sql_ary = $sql_ary['sql_ary'];
$event_filtered_data = $dispatcher->trigger_event('core.display_custom_bbcodes_modify_sql', compact($event_data));
extract($event_filtered_data, EXTR_OVERWRITE);

self::assertEquals($expected, $sql_ary);
}
Expand Down
15 changes: 6 additions & 9 deletions tests/event/custom_bbcodes_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,14 @@ public function test_display_custom_bbcodes($custom_tags, $row, $enabled)
->with(self::equalTo($custom_tags), self::equalTo($row))
->willReturn($custom_tags);

$dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();
$dispatcher = new \phpbb\event\dispatcher();
$dispatcher->addListener('core.display_custom_bbcodes_modify_row', [$this->listener, 'display_custom_bbcodes']);

$event_data = ['custom_tags', 'row'];
$event = new \phpbb\event\data(compact($event_data));
$dispatcher->dispatch('core.display_custom_bbcodes_modify_row', $event);
$event_filtered_data = $dispatcher->trigger_event('core.display_custom_bbcodes_modify_row', compact($event_data));
extract($event_filtered_data, EXTR_OVERWRITE);

$result = $event->get_data_filtered($event_data);

self::assertEquals($custom_tags, $result['custom_tags']);
self::assertEquals($custom_tags, $custom_tags);
}

/**
Expand Down Expand Up @@ -94,11 +92,10 @@ public function test_s9e_allow_custom_bbcodes($in_cron)
->method('allow_custom_bbcodes')
->with($parser);

$dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();
$dispatcher = new \phpbb\event\dispatcher();
$dispatcher->addListener('core.text_formatter_s9e_parser_setup', [$this->listener, 'allow_custom_bbcodes']);

$event_data = ['parser'];
$event = new \phpbb\event\data(compact($event_data));
$dispatcher->dispatch('core.text_formatter_s9e_parser_setup', $event);
$dispatcher->trigger_event('core.text_formatter_s9e_parser_setup', compact($event_data));
}
}
8 changes: 4 additions & 4 deletions tests/event/listener_base.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ class listener_base extends \phpbb_test_case
/** @var \vse\abbc3\core\bbcodes_config */
protected $bbcodes_config;

/** @var \vse\abbc3\core\bbcodes_display|\PHPUnit_Framework_MockObject_MockObject */
/** @var \vse\abbc3\core\bbcodes_display|\PHPUnit\Framework\MockObject\MockObject */
protected $bbcodes_display;

/** @var \vse\abbc3\core\bbcodes_help|\PHPUnit_Framework_MockObject_MockObject */
/** @var \vse\abbc3\core\bbcodes_help|\PHPUnit\Framework\MockObject\MockObject */
protected $bbcodes_help;

/** @var \phpbb\config\config */
protected $config;

/** @var \phpbb\routing\helper|\PHPUnit_Framework_MockObject_MockObject */
/** @var \phpbb\routing\helper|\PHPUnit\Framework\MockObject\MockObject */
protected $helper;

/** @var \phpbb\language\language */
Expand All @@ -33,7 +33,7 @@ class listener_base extends \phpbb_test_case
/** @var \vse\abbc3\event\listener */
protected $listener;

/** @var \phpbb\template\template|\PHPUnit_Framework_MockObject_MockObject */
/** @var \phpbb\template\template|\PHPUnit\Framework\MockObject\MockObject */
protected $template;

/** @var \phpbb\user */
Expand Down
9 changes: 3 additions & 6 deletions tests/event/load_language_on_setup_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,12 @@ public function test_load_language_on_setup($lang_set_ext, $expected_contains)
{
$this->set_listener();

$dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();
$dispatcher = new \phpbb\event\dispatcher();
$dispatcher->addListener('core.user_setup', [$this->listener, 'load_language_on_setup']);

$event_data = ['lang_set_ext'];
$event = new \phpbb\event\data(compact($event_data));
$dispatcher->dispatch('core.user_setup', $event);

$lang_set_ext = $event->get_data_filtered($event_data);
$lang_set_ext = $lang_set_ext['lang_set_ext'];
$event_filtered_data = $dispatcher->trigger_event('core.user_setup', compact($event_data));
extract($event_filtered_data, EXTR_OVERWRITE);

foreach ($expected_contains as $expected)
{
Expand Down
Loading

0 comments on commit b83faa1

Please sign in to comment.