mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-07 20:08:53 +00:00
[ticket/16549] Rewrite at() calls
See https://github.com/sebastianbergmann/phpunit/issues/4297 PHPBB3-16549
This commit is contained in:
parent
72a39920c7
commit
56a7d74588
6 changed files with 100 additions and 148 deletions
|
@ -72,14 +72,10 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case
|
||||||
->with('PHP_AUTH_USER',
|
->with('PHP_AUTH_USER',
|
||||||
\phpbb\request\request_interface::SERVER)
|
\phpbb\request\request_interface::SERVER)
|
||||||
->will($this->returnValue(true));
|
->will($this->returnValue(true));
|
||||||
$this->request->expects($this->at(1))
|
$this->request->expects($this->exactly(2))
|
||||||
->method('server')
|
->method('server')
|
||||||
->with('PHP_AUTH_USER')
|
->withConsecutive(['PHP_AUTH_USER'], ['PHP_AUTH_PW'])
|
||||||
->will($this->returnValue('foobar'));
|
->will($this->onConsecutiveCalls($this->returnValue('foobar'), $this->returnValue('example')));
|
||||||
$this->request->expects($this->at(2))
|
|
||||||
->method('server')
|
|
||||||
->with('PHP_AUTH_PW')
|
|
||||||
->will($this->returnValue('example'));
|
|
||||||
|
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'status' => LOGIN_SUCCESS,
|
'status' => LOGIN_SUCCESS,
|
||||||
|
@ -104,14 +100,10 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case
|
||||||
->with('PHP_AUTH_USER',
|
->with('PHP_AUTH_USER',
|
||||||
\phpbb\request\request_interface::SERVER)
|
\phpbb\request\request_interface::SERVER)
|
||||||
->will($this->returnValue(true));
|
->will($this->returnValue(true));
|
||||||
$this->request->expects($this->at(1))
|
$this->request->expects($this->exactly(2))
|
||||||
->method('server')
|
->method('server')
|
||||||
->with('PHP_AUTH_USER')
|
->withConsecutive(['PHP_AUTH_USER'], ['PHP_AUTH_PW'])
|
||||||
->will($this->returnValue('foobar'));
|
->will($this->onConsecutiveCalls($this->returnValue('foobar'), $this->returnValue('example')));
|
||||||
$this->request->expects($this->at(2))
|
|
||||||
->method('server')
|
|
||||||
->with('PHP_AUTH_PW')
|
|
||||||
->will($this->returnValue('example'));
|
|
||||||
|
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'user_id' => 1,
|
'user_id' => 1,
|
||||||
|
|
|
@ -356,11 +356,8 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
|
||||||
->will($this->returnValue(true));
|
->will($this->returnValue(true));
|
||||||
|
|
||||||
// drop tables
|
// drop tables
|
||||||
$db_tools->expects($this->exactly(2))->method('sql_table_drop');
|
$db_tools->expects($this->exactly(2))->method('sql_table_drop')
|
||||||
$db_tools->expects($this->at(1))->method('sql_table_drop')
|
->withConsecutive([$this->equalTo('dropped_table_1')], [$this->equalTo('dropped_table_2')]);
|
||||||
->with($this->equalTo('dropped_table_1'));
|
|
||||||
$db_tools->expects($this->at(3))->method('sql_table_drop')
|
|
||||||
->with($this->equalTo('dropped_table_2'));
|
|
||||||
|
|
||||||
$db_tools->perform_schema_changes(array(
|
$db_tools->perform_schema_changes(array(
|
||||||
'drop_tables' => array(
|
'drop_tables' => array(
|
||||||
|
@ -384,11 +381,11 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
|
||||||
->will($this->returnValue(true));
|
->will($this->returnValue(true));
|
||||||
|
|
||||||
// drop columns
|
// drop columns
|
||||||
$db_tools->expects($this->exactly(2))->method('sql_column_remove');
|
$db_tools->expects($this->exactly(2))->method('sql_column_remove')
|
||||||
$db_tools->expects($this->at(1))->method('sql_column_remove')
|
->withConsecutive(
|
||||||
->with($this->equalTo('existing_table'), $this->equalTo('dropped_column_1'));
|
[$this->equalTo('existing_table'), $this->equalTo('dropped_column_1')],
|
||||||
$db_tools->expects($this->at(3))->method('sql_column_remove')
|
[$this->equalTo('existing_table'), $this->equalTo('dropped_column_2')]
|
||||||
->with($this->equalTo('existing_table'), $this->equalTo('dropped_column_2'));
|
);
|
||||||
|
|
||||||
$db_tools->perform_schema_changes(array(
|
$db_tools->perform_schema_changes(array(
|
||||||
'drop_columns' => array(
|
'drop_columns' => array(
|
||||||
|
|
|
@ -64,44 +64,33 @@ class phpbb_help_manager_test extends phpbb_test_case
|
||||||
*/
|
*/
|
||||||
public function test_add_block($block_name, $switch, $questions, $switch_expected)
|
public function test_add_block($block_name, $switch, $questions, $switch_expected)
|
||||||
{
|
{
|
||||||
$this->language->expects($this->at(0))
|
$question_ary = $question_ary_upper = $template_call_args = [];
|
||||||
->method('lang')
|
|
||||||
->with($block_name)
|
|
||||||
->willReturn(strtoupper($block_name));
|
|
||||||
$lang_call_count = 1;
|
|
||||||
foreach ($questions as $question => $answer)
|
foreach ($questions as $question => $answer)
|
||||||
{
|
{
|
||||||
$this->language->expects($this->at($lang_call_count))
|
$question_ary = array_merge($question_ary, [[$question], [$answer]]);
|
||||||
->method('lang')
|
$question_ary_upper = array_merge($question_ary_upper, [strtoupper($question), strtoupper($answer)]);
|
||||||
->with($question)
|
$template_call_args = array_merge($template_call_args, [['faq_block.faq_row', [
|
||||||
->willReturn(strtoupper($question));
|
|
||||||
$lang_call_count++;
|
|
||||||
|
|
||||||
$this->language->expects($this->at($lang_call_count))
|
|
||||||
->method('lang')
|
|
||||||
->with($answer)
|
|
||||||
->willReturn(strtoupper($answer));
|
|
||||||
$lang_call_count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->template->expects($this->at(0))
|
|
||||||
->method('assign_block_vars')
|
|
||||||
->with('faq_block', array(
|
|
||||||
'BLOCK_TITLE' => strtoupper($block_name),
|
|
||||||
'SWITCH_COLUMN' => $switch_expected,
|
|
||||||
));
|
|
||||||
$template_call_count = 1;
|
|
||||||
foreach ($questions as $question => $answer)
|
|
||||||
{
|
|
||||||
$this->template->expects($this->at($template_call_count))
|
|
||||||
->method('assign_block_vars')
|
|
||||||
->with('faq_block.faq_row', array(
|
|
||||||
'FAQ_QUESTION' => strtoupper($question),
|
'FAQ_QUESTION' => strtoupper($question),
|
||||||
'FAQ_ANSWER' => strtoupper($answer),
|
'FAQ_ANSWER' => strtoupper($answer),
|
||||||
));
|
]
|
||||||
$template_call_count++;
|
]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->language->expects($this->exactly(count($questions)*2 + 1))
|
||||||
|
->method('lang')
|
||||||
|
->withConsecutive([$block_name], ...$question_ary)
|
||||||
|
->will($this->onConsecutiveCalls(strtoupper($block_name), ...$question_ary_upper));
|
||||||
|
|
||||||
|
$this->template->expects($this->exactly(count($questions) + 1))
|
||||||
|
->method('assign_block_vars')
|
||||||
|
->withConsecutive(
|
||||||
|
['faq_block', [
|
||||||
|
'BLOCK_TITLE' => strtoupper($block_name),
|
||||||
|
'SWITCH_COLUMN' => $switch_expected,
|
||||||
|
]],
|
||||||
|
...$template_call_args
|
||||||
|
);
|
||||||
|
|
||||||
$this->manager->add_block($block_name, $switch, $questions);
|
$this->manager->add_block($block_name, $switch, $questions);
|
||||||
|
|
||||||
$this->assertEquals($switch_expected, $this->manager->switched_column());
|
$this->assertEquals($switch_expected, $this->manager->switched_column());
|
||||||
|
@ -110,8 +99,8 @@ class phpbb_help_manager_test extends phpbb_test_case
|
||||||
public function add_question_data()
|
public function add_question_data()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
array('abc', false, false),
|
array('question1', 'answer1'),
|
||||||
array('def', true, true),
|
array('question2', 'answer2'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,14 +112,13 @@ class phpbb_help_manager_test extends phpbb_test_case
|
||||||
*/
|
*/
|
||||||
public function test_add_question($question, $answer)
|
public function test_add_question($question, $answer)
|
||||||
{
|
{
|
||||||
$this->language->expects($this->at(0))
|
$this->language->expects($this->exactly(2))
|
||||||
->method('lang')
|
->method('lang')
|
||||||
->with($question)
|
->withConsecutive(
|
||||||
->willReturn(strtoupper($question));
|
[$question],
|
||||||
$this->language->expects($this->at(1))
|
[$answer]
|
||||||
->method('lang')
|
)
|
||||||
->with($answer)
|
->will($this->onConsecutiveCalls(strtoupper($question), strtoupper($answer)));
|
||||||
->willReturn(strtoupper($answer));
|
|
||||||
|
|
||||||
$this->template->expects($this->once())
|
$this->template->expects($this->once())
|
||||||
->method('assign_block_vars')
|
->method('assign_block_vars')
|
||||||
|
@ -144,41 +132,33 @@ class phpbb_help_manager_test extends phpbb_test_case
|
||||||
|
|
||||||
public function test_add_block_double_switch()
|
public function test_add_block_double_switch()
|
||||||
{
|
{
|
||||||
$block_name = 'abc';
|
$block_name = ['abc', 'def'];
|
||||||
$switch_expected = true;
|
$switch_expected = [true, false];
|
||||||
|
|
||||||
$this->language->expects($this->at(0))
|
$this->language->expects($this->exactly(2))
|
||||||
->method('lang')
|
->method('lang')
|
||||||
->with($block_name)
|
->withConsecutive([$block_name[0]], [$block_name[1]])
|
||||||
->willReturn(strtoupper($block_name));
|
->will($this->onConsecutiveCalls(strtoupper($block_name[0]), strtoupper($block_name[1])));
|
||||||
|
|
||||||
$this->template->expects($this->at(0))
|
$this->template->expects($this->exactly(2))
|
||||||
->method('assign_block_vars')
|
->method('assign_block_vars')
|
||||||
->with('faq_block', array(
|
->withConsecutive(
|
||||||
'BLOCK_TITLE' => strtoupper($block_name),
|
['faq_block', [
|
||||||
'SWITCH_COLUMN' => $switch_expected,
|
'BLOCK_TITLE' => strtoupper($block_name[0]),
|
||||||
));
|
'SWITCH_COLUMN' => $switch_expected[0],
|
||||||
|
]],
|
||||||
|
['faq_block', [
|
||||||
|
'BLOCK_TITLE' => strtoupper($block_name[1]),
|
||||||
|
'SWITCH_COLUMN' => $switch_expected[1],
|
||||||
|
]]
|
||||||
|
|
||||||
$this->manager->add_block($block_name, true);
|
);
|
||||||
|
|
||||||
|
$this->manager->add_block($block_name[0], true);
|
||||||
$this->assertTrue($this->manager->switched_column());
|
$this->assertTrue($this->manager->switched_column());
|
||||||
|
|
||||||
// Add a second block with switch
|
// Add a second block with switch
|
||||||
$block_name = 'def';
|
$this->manager->add_block($block_name[1], true);
|
||||||
$switch_expected = false;
|
|
||||||
|
|
||||||
$this->language->expects($this->at(0))
|
|
||||||
->method('lang')
|
|
||||||
->with($block_name)
|
|
||||||
->willReturn(strtoupper($block_name));
|
|
||||||
|
|
||||||
$this->template->expects($this->at(0))
|
|
||||||
->method('assign_block_vars')
|
|
||||||
->with('faq_block', array(
|
|
||||||
'BLOCK_TITLE' => strtoupper($block_name),
|
|
||||||
'SWITCH_COLUMN' => $switch_expected,
|
|
||||||
));
|
|
||||||
|
|
||||||
$this->manager->add_block($block_name, true);
|
|
||||||
$this->assertTrue($this->manager->switched_column());
|
$this->assertTrue($this->manager->switched_column());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -288,22 +288,13 @@ class phpbb_textformatter_s9e_factory_test extends phpbb_database_test_case
|
||||||
{
|
{
|
||||||
$this->dispatcher = $this->createMock('phpbb\\event\\dispatcher_interface');
|
$this->dispatcher = $this->createMock('phpbb\\event\\dispatcher_interface');
|
||||||
$this->dispatcher
|
$this->dispatcher
|
||||||
->expects($this->at(0))
|
->expects($this->exactly(2))
|
||||||
->method('trigger_event')
|
->method('trigger_event')
|
||||||
->with(
|
->withConsecutive(
|
||||||
'core.text_formatter_s9e_configure_before',
|
['core.text_formatter_s9e_configure_before', $this->callback(array($this, 'configure_event_callback'))],
|
||||||
$this->callback(array($this, 'configure_event_callback'))
|
['core.text_formatter_s9e_configure_after', $this->callback(array($this, 'configure_event_callback'))]
|
||||||
)
|
)
|
||||||
->will($this->returnArgument(1));
|
->will($this->returnArgument(1));
|
||||||
$this->dispatcher
|
|
||||||
->expects($this->at(1))
|
|
||||||
->method('trigger_event')
|
|
||||||
->with(
|
|
||||||
'core.text_formatter_s9e_configure_after',
|
|
||||||
$this->callback(array($this, 'configure_event_callback'))
|
|
||||||
)
|
|
||||||
->will($this->returnArgument(1));
|
|
||||||
|
|
||||||
$this->get_factory()->get_configurator();
|
$this->get_factory()->get_configurator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -101,15 +101,19 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case
|
||||||
public function test_options($adapter_method, $adapter_arg, $concrete_method, $concrete_arg)
|
public function test_options($adapter_method, $adapter_arg, $concrete_method, $concrete_arg)
|
||||||
{
|
{
|
||||||
$mock = $this->getMockBuilder('s9e\\TextFormatter\\Parser')
|
$mock = $this->getMockBuilder('s9e\\TextFormatter\\Parser')
|
||||||
->setMethods(array($concrete_method))
|
->setMethods([$concrete_method])
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
foreach ((array) $concrete_arg as $i => $concrete_arg)
|
|
||||||
|
$concrete_args = (array) $concrete_arg;
|
||||||
|
array_walk($concrete_args, function(&$value)
|
||||||
{
|
{
|
||||||
$mock->expects($this->at($i))
|
$value = (array) $value;
|
||||||
->method($concrete_method)
|
|
||||||
->with($concrete_arg);
|
|
||||||
}
|
}
|
||||||
|
);
|
||||||
|
$mock->expects($this->exactly(count($concrete_args)))
|
||||||
|
->method($concrete_method)
|
||||||
|
->withConsecutive(...$concrete_args);
|
||||||
|
|
||||||
$cache = new phpbb_mock_cache;
|
$cache = new phpbb_mock_cache;
|
||||||
$cache->put('_foo_parser', $mock);
|
$cache->put('_foo_parser', $mock);
|
||||||
|
@ -141,11 +145,11 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'disable_magic_url', null,
|
'disable_magic_url', null,
|
||||||
'disablePlugin', array('Autoemail', 'Autolink')
|
'disablePlugin', ['Autoemail', 'Autolink']
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'disable_smilies', null,
|
'disable_smilies', null,
|
||||||
'disablePlugin', 'Emoticons'
|
'disablePlugin', ['Emoticons', 'Emoji']
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'enable_bbcode', 'url',
|
'enable_bbcode', 'url',
|
||||||
|
@ -157,11 +161,11 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'enable_magic_url', null,
|
'enable_magic_url', null,
|
||||||
'enablePlugin', array('Autoemail', 'Autolink')
|
'enablePlugin', ['Autoemail', 'Autolink']
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'enable_smilies', null,
|
'enable_smilies', null,
|
||||||
'enablePlugin', 'Emoticons'
|
'enablePlugin', ['Emoticons', 'Emoji']
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -207,22 +211,6 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case
|
||||||
->expects($this->any())
|
->expects($this->any())
|
||||||
->method('trigger_event')
|
->method('trigger_event')
|
||||||
->will($this->returnArgument(1));
|
->will($this->returnArgument(1));
|
||||||
$dispatcher
|
|
||||||
->expects($this->at(1))
|
|
||||||
->method('trigger_event')
|
|
||||||
->with(
|
|
||||||
'core.text_formatter_s9e_parse_before',
|
|
||||||
$this->callback(array($this, 'parse_before_event_callback'))
|
|
||||||
)
|
|
||||||
->will($this->returnArgument(1));
|
|
||||||
$dispatcher
|
|
||||||
->expects($this->at(2))
|
|
||||||
->method('trigger_event')
|
|
||||||
->with(
|
|
||||||
'core.text_formatter_s9e_parse_after',
|
|
||||||
$this->callback(array($this, 'parse_after_event_callback'))
|
|
||||||
)
|
|
||||||
->will($this->returnArgument(1));
|
|
||||||
|
|
||||||
$parser = new \phpbb\textformatter\s9e\parser(
|
$parser = new \phpbb\textformatter\s9e\parser(
|
||||||
$container->get('cache.driver'),
|
$container->get('cache.driver'),
|
||||||
|
@ -230,6 +218,16 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case
|
||||||
$container->get('text_formatter.s9e.factory'),
|
$container->get('text_formatter.s9e.factory'),
|
||||||
$dispatcher
|
$dispatcher
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$dispatcher
|
||||||
|
->expects($this->exactly(2))
|
||||||
|
->method('trigger_event')
|
||||||
|
->withConsecutive(
|
||||||
|
['core.text_formatter_s9e_parse_before', $this->callback(array($this, 'parse_before_event_callback'))],
|
||||||
|
['core.text_formatter_s9e_parse_after', $this->callback(array($this, 'parse_after_event_callback'))]
|
||||||
|
)
|
||||||
|
->will($this->returnArgument(1));
|
||||||
|
|
||||||
$parser->parse('...');
|
$parser->parse('...');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -438,22 +438,6 @@ class phpbb_textformatter_s9e_renderer_test extends phpbb_test_case
|
||||||
->expects($this->any())
|
->expects($this->any())
|
||||||
->method('trigger_event')
|
->method('trigger_event')
|
||||||
->will($this->returnArgument(1));
|
->will($this->returnArgument(1));
|
||||||
$dispatcher
|
|
||||||
->expects($this->at(1))
|
|
||||||
->method('trigger_event')
|
|
||||||
->with(
|
|
||||||
'core.text_formatter_s9e_render_before',
|
|
||||||
$this->callback(array($this, 'render_before_event_callback'))
|
|
||||||
)
|
|
||||||
->will($this->returnArgument(1));
|
|
||||||
$dispatcher
|
|
||||||
->expects($this->at(2))
|
|
||||||
->method('trigger_event')
|
|
||||||
->with(
|
|
||||||
'core.text_formatter_s9e_render_after',
|
|
||||||
$this->callback(array($this, 'render_after_event_callback'))
|
|
||||||
)
|
|
||||||
->will($this->returnArgument(1));
|
|
||||||
|
|
||||||
$renderer = new \phpbb\textformatter\s9e\renderer(
|
$renderer = new \phpbb\textformatter\s9e\renderer(
|
||||||
$container->get('cache.driver'),
|
$container->get('cache.driver'),
|
||||||
|
@ -462,6 +446,16 @@ class phpbb_textformatter_s9e_renderer_test extends phpbb_test_case
|
||||||
$container->get('text_formatter.s9e.factory'),
|
$container->get('text_formatter.s9e.factory'),
|
||||||
$dispatcher
|
$dispatcher
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$dispatcher
|
||||||
|
->expects($this->exactly(2))
|
||||||
|
->method('trigger_event')
|
||||||
|
->withConsecutive(
|
||||||
|
['core.text_formatter_s9e_render_before', $this->callback(array($this, 'render_before_event_callback'))],
|
||||||
|
['core.text_formatter_s9e_render_after', $this->callback(array($this, 'render_after_event_callback'))]
|
||||||
|
)
|
||||||
|
->will($this->returnArgument(1));
|
||||||
|
|
||||||
$renderer->render('<t>...</t>');
|
$renderer->render('<t>...</t>');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue