Merge "Declare dynamic properties"
[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 and description that starts like a variable name' => [
49 <<<'CODE'
50 <?php class MyClass {
51 /** @var array $_GET data from some thing */
52 protected $name;
53 }
54 CODE
55 , <<<'CODE'
56 <?php class MyClass {
57 /** $_GET data from some thing */
58 protected array $name;
59 }
60 CODE
61 ];
62
63 yield 'One-line var with type, name, and description' => [
64 // In this full form, Doxygen understands it just fine.
65 // No changes made.
66 <<<'CODE'
67 <?php class MyClass {
68 /** @var SomeType $name Some description */
69 protected $name;
70 }
71 CODE
72 ];
73
74 yield 'Multi-line var with type' => [
75 <<<'CODE'
76 <?php class MyClass {
77 /**
78 * @var SomeType
79 */
80 protected $name;
81 }
82 CODE
83 , <<<'CODE'
84 <?php class MyClass {
85 /**
86 *
87 */
88 protected SomeType $name;
89 }
90 CODE
91 ];
92
93 yield 'Multi-line var with type and description' => [
94 <<<'CODE'
95 <?php class MyClass {
96 /**
97 * Some description
98 * @var SomeType
99 */
100 protected $name;
101 }
102 CODE
103 , <<<'CODE'
104 <?php class MyClass {
105 /**
106 * Some description
107 *
108 */
109 protected SomeType $name;
110 }
111 CODE
112 ];
113
114 yield 'Multi-line var with type, name, and description' => [
115 <<<'CODE'
116 <?php class MyClass {
117 /**
118 * Some description
119 * @var SomeType $name
120 */
121 protected $name;
122 }
123 CODE
124 , <<<'CODE'
125 <?php class MyClass {
126 /**
127 * Some description
128 * @var SomeType $name
129 */
130 protected $name;
131 }
132 CODE
133 ];
134 }
135
136 /**
137 * @dataProvider provideFilter
138 */
139 public function testFilter( $source, $expected = null ) {
140 if ( $expected === null ) {
141 $expected = $source;
142 }
143 $this->assertSame( $expected, MWDoxygenFilter::filter( $source ), 'Source code' );
144 }
145 }