docs: Factor out MWDoxygenFilter from mwdoc-filter.php with tests
[lhc/web/wiklou.git] / tests / phpunit / maintenance / MWDoxygenFilterTest.php
1 <?php
2
3 /**
4 * @covers MWDoxygenFilter
5 */
6 class MWDoxygenFilterTest extends \PHPUnit\Framework\TestCase {
7
8 public static function provideFilter() {
9 yield 'No @var' => [
10 <<<'CODE'
11 <?php class MyClass {
12 /** Some Words here */
13 protected $name;
14 }
15 CODE
16 ];
17
18 yield 'One-line var with type' => [
19 <<<'CODE'
20 <?php class MyClass {
21 /** @var SomeType */
22 protected $name;
23 }
24 CODE
25 , <<<'CODE'
26 <?php class MyClass {
27 /** */
28 protected SomeType $name;
29 }
30 CODE
31 ];
32
33 yield 'One-line var with type and description' => [
34 <<<'CODE'
35 <?php class MyClass {
36 /** @var SomeType Some description */
37 protected $name;
38 }
39 CODE
40 , <<<'CODE'
41 <?php class MyClass {
42 /** Some description */
43 protected SomeType $name;
44 }
45 CODE
46 ];
47
48 yield 'One-line var with type, name, and description' => [
49 // In this full form, Doxygen understands it just fine.
50 // No changes made.
51 <<<'CODE'
52 <?php class MyClass {
53 /** @var SomeType $name Some description */
54 protected $name;
55 }
56 CODE
57 ];
58
59 yield 'Multi-line var with type' => [
60 <<<'CODE'
61 <?php class MyClass {
62 /**
63 * @var SomeType
64 */
65 protected $name;
66 }
67 CODE
68 , <<<'CODE'
69 <?php class MyClass {
70 /**
71 *
72 */
73 protected SomeType $name;
74 }
75 CODE
76 ];
77
78 yield 'Multi-line var with type and description' => [
79 <<<'CODE'
80 <?php class MyClass {
81 /**
82 * Some description
83 * @var SomeType
84 */
85 protected $name;
86 }
87 CODE
88 , <<<'CODE'
89 <?php class MyClass {
90 /**
91 * Some description
92 *
93 */
94 protected SomeType $name;
95 }
96 CODE
97 ];
98
99 yield 'Multi-line var with type, name, and description' => [
100 <<<'CODE'
101 <?php class MyClass {
102 /**
103 * Some description
104 * @var SomeType $name
105 */
106 protected $name;
107 }
108 CODE
109 , <<<'CODE'
110 <?php class MyClass {
111 /**
112 * Some description
113 * @var SomeType $name
114 */
115 protected $name;
116 }
117 CODE
118 ];
119 }
120
121 /**
122 * @dataProvider provideFilter
123 */
124 public function testFilter( $source, $expected = null ) {
125 if ( $expected === null ) {
126 $expected = $source;
127 }
128 $this->assertSame( $expected, MWDoxygenFilter::filter( $source ), 'Source code' );
129 }
130 }