Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
11.48% covered (danger)
11.48%
59 / 514
51.22% covered (warning)
51.22%
21 / 41
CRAP
0.00% covered (danger)
0.00%
0 / 1
phpbb_event_php_exporter_test
11.48% covered (danger)
11.48%
59 / 514
51.22% covered (warning)
51.22%
21 / 41
1207.04
0.00% covered (danger)
0.00%
0 / 1
 setUp
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 crawl_php_file_data
0.00% covered (danger)
0.00%
0 / 84
0.00% covered (danger)
0.00%
0 / 1
2
 test_crawl_php_file
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 crawl_php_file_throws_data
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 test_crawl_php_file_throws
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 validate_since_data
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 test_validate_since
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 validate_since_throws_data
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 test_validate_since_throws
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 validate_event_data
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 test_validate_event
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 validate_event_throws_data
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 test_validate_event_throws
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 validate_vars_docblock_array_data
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 test_validate_vars_docblock_array
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 validate_vars_docblock_array_throws_data
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 test_validate_vars_docblock_array_throws
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 get_dispatch_name_data
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
2
 test_get_dispatch_name
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 get_dispatch_name_throws_data
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
2
 test_get_dispatch_name_throws
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 get_trigger_event_name_data
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
2
 test_get_trigger_event_name
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 get_trigger_event_name_throws_data
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
2
 test_get_trigger_event_name_throws
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 get_vars_from_array_data
0.00% covered (danger)
0.00%
0 / 22
0.00% covered (danger)
0.00%
0 / 1
2
 test_get_vars_from_array
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 get_vars_from_array_throws_data
0.00% covered (danger)
0.00%
0 / 81
0.00% covered (danger)
0.00%
0 / 1
2
 test_get_vars_from_array_throws
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 get_vars_from_docblock_data
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
2
 test_get_vars_from_docblock
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 get_vars_from_docblock_throws_data
0.00% covered (danger)
0.00%
0 / 41
0.00% covered (danger)
0.00%
0 / 1
2
 test_get_vars_from_docblock_throws
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 find_since_data
0.00% covered (danger)
0.00%
0 / 24
0.00% covered (danger)
0.00%
0 / 1
2
 test_find_since
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 find_since_throws_data
0.00% covered (danger)
0.00%
0 / 48
0.00% covered (danger)
0.00%
0 / 1
2
 test_find_since_throws
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 find_description_data
0.00% covered (danger)
0.00%
0 / 26
0.00% covered (danger)
0.00%
0 / 1
2
 test_find_description
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 find_description_throws_data
0.00% covered (danger)
0.00%
0 / 44
0.00% covered (danger)
0.00%
0 / 1
2
 test_find_description_throws
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3*
4* This file is part of the phpBB Forum Software package.
5*
6* @copyright (c) phpBB Limited <https://www.phpbb.com>
7* @license GNU General Public License, version 2 (GPL-2.0)
8*
9* For full copyright and license information, please see
10* the docs/CREDITS.txt file.
11*
12*/
13
14class phpbb_event_php_exporter_test extends phpbb_test_case
15{
16    /** @var \phpbb\event\php_exporter */
17    protected $exporter;
18
19    protected function setUp(): void
20    {
21        parent::setUp();
22        $this->exporter = new \phpbb\event\php_exporter(__DIR__ . '/fixtures/');
23    }
24
25    static public function crawl_php_file_data()
26    {
27        return array(
28            array(
29                'default.test',
30                array(
31                    'default.dispatch'    => array(
32                        'event'            => 'default.dispatch',
33                        'file'            => 'default.test',
34                        'arguments'        => array(),
35                        'since'            => '3.1.0-b2',
36                        'description'    => 'Description',
37                    ),
38                ),
39            ),
40            array(
41                'event_migration.test',
42                array(
43                    'core.ucp_pm_view_message'    => array(
44                        'event'            => 'core.ucp_pm_view_message',
45                        'file'            => 'event_migration.test',
46                        'arguments'        => array('cp_row', 'folder', 'folder_id', 'id', 'message_row', 'mode', 'msg_data', 'msg_id', 'user_info'),
47                        'since'            => '3.1.0-a1',
48                        'description'    => 'Modify pm and sender data before it is assigned to the template',
49                    ),
50                ),
51            ),
52            array(
53                'extra_description.test',
54                array(
55                    'extra_description.dispatch'    => array(
56                        'event'            => 'extra_description.dispatch',
57                        'file'            => 'extra_description.test',
58                        'arguments'        => array(),
59                        'since'            => '3.1.0-b2',
60                        'description'    => 'Description<br><br>NOTE: This will also be exported',
61                    ),
62                ),
63            ),
64            array(
65                'trigger.test',
66                array(
67                    'core.trigger'    => array(
68                        'event'            => 'core.trigger',
69                        'file'            => 'trigger.test',
70                        'arguments'        => array('cp_row', 'current_row_number', 'end', 'row', 'start'),
71                        'since'            => '3.1.0-a3',
72                        'description'    => 'Event after the post data has been assigned to the template',
73                    ),
74                ),
75            ),
76            array(
77                'trigger_wspace.test',
78                array(
79                    'core.trigger'    => array(
80                        'event'            => 'core.trigger',
81                        'file'            => 'trigger_wspace.test',
82                        'arguments'        => array('cp_row', 'current_row_number', 'end', 'row', 'start'),
83                        'since'            => '3.1.0-a3',
84                        'description'    => 'Event after the post data has been assigned to the template',
85                    ),
86                ),
87            ),
88            array(
89                'trigger_many_vars.test',
90                array(
91                    'core.posting_modify_template_vars'    => array(
92                        'event'            => 'core.posting_modify_template_vars',
93                        'file'            => 'trigger_many_vars.test',
94                        'arguments'        => array(
95                            'cancel', 'delete', 'error', 'form_enctype', 'forum_id',
96                            'load', 'message_parser', 'mode', 'moderators', 'page_data',
97                            'page_title', 'post_data', 'post_id', 'preview', 'refresh',
98                            's_action', 's_hidden_fields', 's_topic_icons', 'save',
99                            'submit', 'topic_id',
100                        ),
101                        'since'            => '3.1.0-a1',
102                        'description'    => 'This event allows you to modify template variables for the posting screen',
103                    ),
104                ),
105            ),
106            array(
107                'none.test',
108                array(),
109            ),
110        );
111    }
112
113    /**
114    * @dataProvider crawl_php_file_data
115    */
116    public function test_crawl_php_file($file, $expected)
117    {
118        $this->exporter->crawl_php_file($file);
119        $this->assertEquals($expected, $this->exporter->get_events());
120    }
121
122    static public function crawl_php_file_throws_data()
123    {
124        return array(
125            array('missing_var.test', 2),
126            array('duplicate_event.test', 10),
127        );
128    }
129
130    /**
131    * @dataProvider crawl_php_file_throws_data
132    */
133    public function test_crawl_php_file_throws($file, $exception_code)
134    {
135        $this->expectException('LogicException');
136        $this->expectExceptionCode($exception_code);
137        $this->exporter->crawl_php_file($file);
138    }
139
140    static public function validate_since_data()
141    {
142        return array(
143            array('* @since 3.1.0-a1', '3.1.0-a1'),
144            array('* @since 3.1.0-b3', '3.1.0-b3'),
145            array('    * @since 3.1.0-b3', '3.1.0-b3'),
146            array('* @since 3.1.0-RC2', '3.1.0-RC2'),
147            array(' * @since 3.1.0-a1', '3.1.0-a1'),
148        );
149    }
150
151    /**
152    * @dataProvider validate_since_data
153    */
154    public function test_validate_since($since, $expected)
155    {
156        $this->assertEquals($expected, $this->exporter->validate_since($since));
157    }
158
159    static public function validate_since_throws_data()
160    {
161        return array(
162            array('* @since 3.1.0-a1 '),
163            array('* @since 3.1.0-a1 bertie is cool'),
164            array('bertie* @since 3.1.0-a1'),
165            array('* @since 3.1-A2'),
166            array('* @since 3.1.0-rc1'),
167        );
168    }
169
170    /**
171    * @dataProvider validate_since_throws_data
172    */
173    public function test_validate_since_throws($since)
174    {
175        $this->expectException('LogicException');
176        $this->exporter->validate_since($since);
177    }
178
179    static public function validate_event_data()
180    {
181        return array(
182            array('test.event', '* @event test.event', 'test.event'),
183            array('test.event2', '    * @event test.event2', 'test.event2'),
184            array('test.event', ' * @event test.event', 'test.event'),
185        );
186    }
187
188    /**
189    * @dataProvider validate_event_data
190    */
191    public function test_validate_event($event_name, $event, $expected)
192    {
193        $this->assertEquals($expected, $this->exporter->validate_event($event_name, $event));
194    }
195
196    static public function validate_event_throws_data()
197    {
198        return array(
199            array('test.event', '* @event test.event bertie is cool', 2),
200            array('test.event', 'bertie* @event test.event', 2),
201        );
202    }
203
204    /**
205    * @dataProvider validate_event_throws_data
206    */
207    public function test_validate_event_throws($event_name, $event, $exception_code)
208    {
209        $this->expectException('LogicException');
210        $this->expectExceptionCode($exception_code);
211        $this->exporter->validate_event($event_name, $event);
212    }
213
214    static public function validate_vars_docblock_array_data()
215    {
216        return array(
217            array(array('abc', 'def'), array('abc', 'def')),
218        );
219    }
220
221    /**
222    * @dataProvider validate_vars_docblock_array_data
223    */
224    public function test_validate_vars_docblock_array($vars_array, $vars_docblock)
225    {
226        $this->assertNull($this->exporter->validate_vars_docblock_array($vars_array, $vars_docblock));
227    }
228
229    static public function validate_vars_docblock_array_throws_data()
230    {
231        return array(
232            array(array('abc', 'def'), array()),
233            array(array('abc', 'def'), array('abc')),
234            array(array('abc', 'defg'), array('abc', 'def')),
235            array(array('abc'), array('abc', 'def')),
236            array(array(), array('abc', 'def')),
237        );
238    }
239
240    /**
241    * @dataProvider validate_vars_docblock_array_throws_data
242    */
243    public function test_validate_vars_docblock_array_throws($vars_array, $vars_docblock)
244    {
245        $this->expectException('LogicException');
246        $this->exporter->validate_vars_docblock_array($vars_array, $vars_docblock);
247    }
248
249    static public function get_dispatch_name_data()
250    {
251        return array(
252            array("\$phpbb_dispatcher->dispatch('dispatch.one2');", 'dispatch.one2'),
253            array("\t\$phpbb_dispatcher->dispatch('dispatch.one2.thr_ee4');", 'dispatch.one2.thr_ee4'),
254            array("\$this->dispatcher->dispatch('dispatch.one2');", 'dispatch.one2'),
255            array("\$phpbb_dispatcher->dispatch('dis_patch.one');", 'dis_patch.one'),
256            array("\$phpbb_dispatcher->dispatch(['dis_patch.one', 'dis_patch.one2']);", 'dis_patch.one'),
257            array("\$phpbb_dispatcher->dispatch(['dis_patch.one', 'dis_patch.one2', 'dis_patch.two3']);", 'dis_patch.one'),
258        );
259    }
260
261    /**
262    * @dataProvider get_dispatch_name_data
263    */
264    public function test_get_dispatch_name($event_line, $expected)
265    {
266        $this->exporter->set_content(array($event_line));
267        $this->assertEquals($expected, $this->exporter->get_event_name(0, true));
268    }
269
270    static public function get_dispatch_name_throws_data()
271    {
272        return array(
273            array("\$phpbb_dispatcher->dispatch();"),
274            array("\$phpbb_dispatcher->dispatch('');"),
275            array("\$phpbb_dispatcher->dispatch('dispatch.2one');"),
276            array("\$phpbb_dispatcher->dispatch('dispatch');"),
277            array("\$phpbb_dispatcher->dispatch(['dispatch.one']);"),
278            array("\$phpbb_dispatcher->dispatch(array('dispatch.one', 'dispatch.one2'));"),
279        );
280    }
281
282    /**
283    * @dataProvider get_dispatch_name_throws_data
284    */
285    public function test_get_dispatch_name_throws($event_line)
286    {
287        $this->expectException('LogicException');
288        $this->exporter->set_content(array($event_line));
289        $this->exporter->get_event_name(0, true);
290    }
291
292    static public function get_trigger_event_name_data()
293    {
294        return array(
295            array("extract(\$phpbb_dispatcher->trigger_event('dispatch.one2', compact(\$vars)));", 'dispatch.one2'),
296            array("\textract(\$phpbb_dispatcher->trigger_event('dispatch.one2.thr_ee4', compact(\$vars)));", 'dispatch.one2.thr_ee4'),
297            array("extract(\$this->dispatcher->trigger_event('dispatch.one2', compact(\$vars)));", 'dispatch.one2'),
298            array("extract(\$phpbb_dispatcher->trigger_event('dis_patch.one', compact(\$vars)));", 'dis_patch.one'),
299            array("extract(\$phpbb_dispatcher->trigger_event(['dis_patch.one', 'dis_patch.one2'], compact(\$vars)));", 'dis_patch.one'),
300            array("extract(\$phpbb_dispatcher->trigger_event(['dis_patch.one', 'dis_patch.one2', 'dis_patch.two3'], compact(\$vars)));", 'dis_patch.one'),
301        );
302    }
303
304    /**
305    * @dataProvider get_trigger_event_name_data
306    */
307    public function test_get_trigger_event_name($event_line, $expected)
308    {
309        $this->exporter->set_content(array($event_line));
310        $this->assertEquals($expected, $this->exporter->get_event_name(0, false));
311    }
312
313    static public function get_trigger_event_name_throws_data()
314    {
315        return array(
316            array("extract(\$phpbb_dispatcher->trigger_event());"),
317            array("extract(\$phpbb_dispatcher->trigger_event(''));"),
318            array("extract(\$phpbb_dispatcher->trigger_event('dispatch.2one'));"),
319            array("extract(\$phpbb_dispatcher->trigger_event('dispatch'));"),
320            array("extract(\$phpbb_dispatcher->trigger_event('dispatch.one', \$vars));"),
321            array("extract(\$phpbb_dispatcher->trigger_event('dispatch.one', compact(\$var)));"),
322            array("extract(\$phpbb_dispatcher->trigger_event('dispatch.one', compact(\$array)));"),
323            array("extract(\$phpbb_dispatcher->trigger_event(['dispatch.one'], compact(\$vars)));"),
324            array("\$phpbb_dispatcher->trigger_event('dis_patch.one', compact(\$vars));", 'dis_patch.one'),
325        );
326    }
327
328    /**
329    * @dataProvider get_trigger_event_name_throws_data
330    */
331    public function test_get_trigger_event_name_throws($event_line)
332    {
333        $this->expectException('LogicException');
334        $this->exporter->set_content(array($event_line));
335        $this->exporter->get_event_name(0, false);
336    }
337
338    static public function get_vars_from_array_data()
339    {
340        return array(
341            array(
342                array(
343                    '/**',
344                    '*/',
345                    '$vars = array(\'bertie\');',
346                    '$phpbb_dispatcher->dispatch(\'test\');',
347                ),
348                3,
349                array('bertie'),
350            ),
351            array(
352                array(
353                    "\t/**",
354                    "\t*/",
355                    "\t\$vars = array('_Strange123', 'phpBB_Test');",
356                    "\t\$this->dispatcher->dispatch('test');",
357                ),
358                3,
359                array('_Strange123', 'phpBB_Test'),
360            ),
361        );
362    }
363
364    /**
365    * @dataProvider get_vars_from_array_data
366    */
367    public function test_get_vars_from_array($lines, $event_line, $expected)
368    {
369        $this->exporter->set_current_event('', $event_line);
370        $this->exporter->set_content($lines);
371        $this->assertEquals($expected, $this->exporter->get_vars_from_array());
372    }
373
374    static public function get_vars_from_array_throws_data()
375    {
376        return array(
377            array(
378                array(
379                    '/**',
380                    '*/',
381                    '$phpbb_dispatcher->trigger_event(\'test\', compact($vars));',
382                ),
383                2,
384                1,
385            ),
386            array(
387                array(
388                    '/**',
389                    '*/',
390                    '$vars = $bertie;',
391                    '$phpbb_dispatcher->trigger_event(\'test\', compact($vars));',
392                ),
393                3,
394                1,
395            ),
396            array(
397                array(
398                    '/**',
399                    '*/',
400                    '$vars = array(\'$bertie\');',
401                    '$phpbb_dispatcher->trigger_event(\'test\', compact($vars));',
402                ),
403                3,
404                1,
405            ),
406            array(
407                array(
408                    '/**',
409                    '*/',
410                    '$vars = array();',
411                    '$phpbb_dispatcher->trigger_event(\'test\', compact($vars));',
412                ),
413                3,
414                1,
415            ),
416            array(
417                array(
418                    '/**',
419                    '*/',
420                    '$vars = array(\'t1\', \'t2\', \'t3\', \'t4\', \'t5\', \'t6\', \'t7\');',
421                    '$phpbb_dispatcher->trigger_event(\'test\', compact($vars));',
422                ),
423                3,
424                2,
425            ),
426            array(
427                array(
428                    '/**',
429                    '*/',
430                    '$vars = array(\'test2\', \'\');',
431                    '$phpbb_dispatcher->trigger_event(\'test\', compact($vars));',
432                ),
433                3,
434                3,
435            ),
436            array(
437                array(
438                    '/**',
439                    '*/',
440                    '$vars = array(\'bertie\'\');',
441                    '$phpbb_dispatcher->trigger_event(\'test\', compact($vars));',
442                ),
443                3,
444                3,
445            ),
446            array(
447                array(
448                    '/**',
449                    '*/',
450                    '$vars = array(\'bertie\',\'basically_valid\');',
451                    '$phpbb_dispatcher->trigger_event(\'test\', compact($vars));',
452                ),
453                3,
454                3,
455            ),
456        );
457    }
458
459    /**
460    * @dataProvider get_vars_from_array_throws_data
461    */
462    public function test_get_vars_from_array_throws($lines, $event_line, $exception_code)
463    {
464        $this->expectException('LogicException');
465        $this->expectExceptionCode($exception_code);
466
467        $this->exporter->set_current_event('', $event_line);
468        $this->exporter->set_content($lines);
469        $this->exporter->get_vars_from_array();
470    }
471
472    static public function get_vars_from_docblock_data()
473    {
474        return array(
475            array(
476                array(
477                    '/**',
478                    '* @var    int    name1    Description',
479                    '* @var    array    name2    Description test',
480                    '*/',
481                    '$phpbb_dispatcher->dispatch(\'test\');',
482                ),
483                4,
484                array('name1', 'name2'),
485            ),
486        );
487    }
488
489    /**
490    * @dataProvider get_vars_from_docblock_data
491    */
492    public function test_get_vars_from_docblock($lines, $event_line, $expected)
493    {
494        $this->exporter->set_current_event('', $event_line);
495        $this->exporter->set_content($lines);
496        $this->assertEquals($expected, $this->exporter->get_vars_from_docblock());
497    }
498
499    static public function get_vars_from_docblock_throws_data()
500    {
501        return array(
502            array(
503                array(
504                    '$vars = array();',
505                    '$phpbb_dispatcher->dispatch(\'test\');',
506                ),
507                1,
508                2,
509            ),
510            array(
511                array(
512                    '/**',
513                    '* @var    int    name1',
514                    '* @var    array    name2    Description test',
515                    '*/',
516                    '$phpbb_dispatcher->dispatch(\'test\');',
517                ),
518                4,
519                1,
520            ),
521            array(
522                array(
523                    '/**',
524                    '*/',
525                    '$phpbb_dispatcher->dispatch(\'test\');',
526                ),
527                2,
528                3,
529            ),
530            array(
531                array(
532                    '/**',
533                    '* @var    int    name1    Description',
534                    '* @var    array    $name2    Description',
535                    '*/',
536                    '$phpbb_dispatcher->dispatch(\'test\');',
537                ),
538                4,
539                4,
540            ),
541        );
542    }
543
544    /**
545    * @dataProvider get_vars_from_docblock_throws_data
546    */
547    public function test_get_vars_from_docblock_throws($lines, $event_line, $exception_code)
548    {
549        $this->expectException('LogicException');
550        $this->expectExceptionCode($exception_code);
551
552        $this->exporter->set_current_event('', $event_line);
553        $this->exporter->set_content($lines);
554        $this->exporter->get_vars_from_docblock();
555    }
556
557    static public function find_since_data()
558    {
559        return array(
560            array(
561                array(
562                    '/**',
563                    '* @since 3.1.0-a1',
564                    '*/',
565                    '$phpbb_dispatcher->dispatch(\'test\');',
566                ),
567                3,
568                1,
569            ),
570            array(
571                array(
572                    '* @since 3.1.0-a1',
573                    '/**',
574                    '* @since 3.1.0-a1',
575                    '* @changed 3.1.0-a2',
576                    '*/',
577                    '$phpbb_dispatcher->dispatch(\'test\');',
578                ),
579                5,
580                2,
581            ),
582        );
583    }
584
585    /**
586    * @dataProvider find_since_data
587    */
588    public function test_find_since($lines, $event_line, $expected)
589    {
590        $this->exporter->set_current_event('', $event_line);
591        $this->exporter->set_content($lines);
592        $this->assertEquals($expected, $this->exporter->find_since());
593    }
594
595    static public function find_since_throws_data()
596    {
597        return array(
598            array(
599                array(
600                    '/**',
601                    '* @since 3.1.0-a1',
602                    '*/',
603                    '/**',
604                    '*/',
605                    '$phpbb_dispatcher->dispatch(\'test\');',
606                ),
607                5,
608                1,
609            ),
610            array(
611                array(
612                    '/**',
613                    '* @changed 3.1.0-a1',
614                    '* @changed 3.1.0-a2',
615                    '* @changed 3.1.0-a3',
616                    '*/',
617                    '$phpbb_dispatcher->dispatch(\'test\');',
618                ),
619                5,
620                2,
621            ),
622            array(
623                array(
624                    '/**',
625                    '* @since 3.1.0-a2',
626                    '* @var',
627                    '*/',
628                    '$phpbb_dispatcher->dispatch(\'test\');',
629                ),
630                4,
631                3,
632            ),
633            array(
634                array(
635                    '/**',
636                    '* @since 3.1.0-a2',
637                    '* @event',
638                    '*/',
639                    '$phpbb_dispatcher->dispatch(\'test\');',
640                ),
641                4,
642                3,
643            ),
644        );
645    }
646
647    /**
648    * @dataProvider find_since_throws_data
649    */
650    public function test_find_since_throws($lines, $event_line, $exception_code)
651    {
652        $this->expectException('LogicException');
653        $this->expectExceptionCode($exception_code);
654
655        $this->exporter->set_current_event('', $event_line);
656        $this->exporter->set_content($lines);
657        $this->exporter->find_since();
658    }
659
660    static public function find_description_data()
661    {
662        return array(
663            array(
664                array(
665                    '/**',
666                    '* Hello Bertie!',
667                    '* @since 3.1.0-a1',
668                    '*/',
669                    '$phpbb_dispatcher->dispatch(\'test\');',
670                ),
671                4,
672                1,
673            ),
674            array(
675                array(
676                    '    /**',
677                    '    * Hello Bertie!',
678                    '    *',
679                    '    * @since 3.1.0-a1',
680                    '    * @changed 3.1.0-a2',
681                    '    */',
682                    '    $phpbb_dispatcher->dispatch(\'test\');',
683                ),
684                6,
685                1,
686            ),
687        );
688    }
689
690    /**
691    * @dataProvider find_description_data
692    */
693    public function test_find_description($lines, $event_line, $expected)
694    {
695        $this->exporter->set_current_event('', $event_line);
696        $this->exporter->set_content($lines);
697        $this->assertEquals($expected, $this->exporter->find_description());
698    }
699
700    static public function find_description_throws_data()
701    {
702        return array(
703            array(
704                array(
705                    '$vars = array();',
706                    '$phpbb_dispatcher->dispatch(\'test\');',
707                ),
708                1,
709                1,
710            ),
711            array(
712                array(
713                    '/**',
714                    '* @changed 3.1.0-a1',
715                    '* @changed 3.1.0-a2',
716                    '* @changed 3.1.0-a3',
717                    '*/',
718                    '$phpbb_dispatcher->dispatch(\'test\');',
719                ),
720                5,
721                2,
722            ),
723            array(
724                array(
725                    '/**',
726                    '*',
727                    '* @since 3.1.0-a2',
728                    '*/',
729                    '$phpbb_dispatcher->dispatch(\'test\');',
730                ),
731                4,
732                2,
733            ),
734            array(
735                array(
736                    '/**',
737                    '* ',
738                    '* @event',
739                    '*/',
740                    '$phpbb_dispatcher->dispatch(\'test\');',
741                ),
742                4,
743                2,
744            ),
745        );
746    }
747
748    /**
749    * @dataProvider find_description_throws_data
750    */
751    public function test_find_description_throws($lines, $event_line, $exception_code)
752    {
753        $this->expectException('LogicException');
754        $this->expectExceptionCode($exception_code);
755
756        $this->exporter->set_current_event('', $event_line);
757        $this->exporter->set_content($lines);
758        $this->exporter->find_description();
759    }
760}