Skip to content

Commit 37b8c39

Browse files
committed
Add tests for short/long type sniffs and utils
1 parent f96782e commit 37b8c39

9 files changed

Lines changed: 276 additions & 45 deletions
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
// phpcs:set Squiz.Commenting.FunctionComment useShortTypes false
4+
5+
/**
6+
* Type check for function with both long and short types.
7+
*
8+
* @param bool $a1 Comment here.
9+
* @param boolean $a2 Comment here.
10+
* @param int $a3 Comment here.
11+
* @param integer $a4 Comment here.
12+
*
13+
* @return void
14+
*/
15+
function mixedLongAndShortUseLong(bool $a1, bool $a2, int $a3, int $a4)
16+
{
17+
}//end mixedLongAndShortUseLong()
18+
19+
// phpcs:set Squiz.Commenting.FunctionComment useShortTypes true
20+
21+
/**
22+
* Type check for function with both long and short types.
23+
*
24+
* @param bool $a1 Comment here.
25+
* @param boolean $a2 Comment here.
26+
* @param int $a3 Comment here.
27+
* @param integer $a4 Comment here.
28+
*
29+
* @return void
30+
*/
31+
function mixedLongAndShortUseShort(bool $a1, bool $a2, int $a3, int $a4)
32+
{
33+
}//end mixedLongAndShortUseShort()
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
// phpcs:set Squiz.Commenting.FunctionComment useShortTypes false
4+
5+
/**
6+
* Type check for function with both long and short types.
7+
*
8+
* @param boolean $a1 Comment here.
9+
* @param boolean $a2 Comment here.
10+
* @param integer $a3 Comment here.
11+
* @param integer $a4 Comment here.
12+
*
13+
* @return void
14+
*/
15+
function mixedLongAndShortUseLong(bool $a1, bool $a2, int $a3, int $a4)
16+
{
17+
}//end mixedLongAndShortUseLong()
18+
19+
// phpcs:set Squiz.Commenting.FunctionComment useShortTypes true
20+
21+
/**
22+
* Type check for function with both long and short types.
23+
*
24+
* @param bool $a1 Comment here.
25+
* @param bool $a2 Comment here.
26+
* @param int $a3 Comment here.
27+
* @param int $a4 Comment here.
28+
*
29+
* @return void
30+
*/
31+
function mixedLongAndShortUseShort(bool $a1, bool $a2, int $a3, int $a4)
32+
{
33+
}//end mixedLongAndShortUseShort()

src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,14 @@ public function getErrorList($testFile = '')
181181
8 => 1,
182182
];
183183

184+
case 'FunctionCommentUnitTest.3.inc':
185+
return [
186+
8 => 1,
187+
10 => 1,
188+
25 => 1,
189+
27 => 1,
190+
];
191+
184192
default:
185193
return [];
186194
}

src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc renamed to src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.1.inc

File renamed without changes.

src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc.fixed renamed to src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.1.inc.fixed

File renamed without changes.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
// phpcs:set Squiz.Commenting.VariableComment useShortTypes false
4+
5+
class UsingLongTypes
6+
{
7+
/**
8+
* @var bool
9+
*/
10+
public $typeBool;
11+
12+
/**
13+
* @var boolean
14+
*/
15+
public $typeBoolean;
16+
17+
/**
18+
* @var int
19+
*/
20+
public $typeInt;
21+
22+
/**
23+
* @var integer
24+
*/
25+
public $typeInteger;
26+
}
27+
28+
// phpcs:set Squiz.Commenting.VariableComment useShortTypes true
29+
30+
class UsingShortTypes
31+
{
32+
/**
33+
* @var bool
34+
*/
35+
public $typeBool;
36+
37+
/**
38+
* @var boolean
39+
*/
40+
public $typeBoolean;
41+
42+
/**
43+
* @var int
44+
*/
45+
public $typeInt;
46+
47+
/**
48+
* @var integer
49+
*/
50+
public $typeInteger;
51+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
// phpcs:set Squiz.Commenting.VariableComment useShortTypes false
4+
5+
class UsingLongTypes
6+
{
7+
/**
8+
* @var boolean
9+
*/
10+
public $typeBool;
11+
12+
/**
13+
* @var boolean
14+
*/
15+
public $typeBoolean;
16+
17+
/**
18+
* @var integer
19+
*/
20+
public $typeInt;
21+
22+
/**
23+
* @var integer
24+
*/
25+
public $typeInteger;
26+
}
27+
28+
// phpcs:set Squiz.Commenting.VariableComment useShortTypes true
29+
30+
class UsingShortTypes
31+
{
32+
/**
33+
* @var bool
34+
*/
35+
public $typeBool;
36+
37+
/**
38+
* @var bool
39+
*/
40+
public $typeBoolean;
41+
42+
/**
43+
* @var int
44+
*/
45+
public $typeInt;
46+
47+
/**
48+
* @var int
49+
*/
50+
public $typeInteger;
51+
}

src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.php

Lines changed: 70 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -27,47 +27,63 @@ final class VariableCommentUnitTest extends AbstractSniffTestCase
2727
* The key of the array should represent the line number and the value
2828
* should represent the number of errors that should occur on that line.
2929
*
30+
* @param string $testFile The name of the test file being tested.
31+
*
3032
* @return array<int, int>
3133
*/
32-
public function getErrorList()
34+
public function getErrorList($testFile = '')
3335
{
34-
return [
35-
21 => 1,
36-
24 => 1,
37-
56 => 1,
38-
64 => 1,
39-
73 => 1,
40-
84 => 1,
41-
130 => 1,
42-
136 => 1,
43-
144 => 1,
44-
152 => 1,
45-
160 => 1,
46-
168 => 1,
47-
176 => 1,
48-
184 => 1,
49-
192 => 1,
50-
200 => 1,
51-
208 => 1,
52-
216 => 1,
53-
224 => 1,
54-
232 => 1,
55-
240 => 1,
56-
248 => 1,
57-
256 => 1,
58-
264 => 1,
59-
272 => 1,
60-
280 => 1,
61-
290 => 1,
62-
294 => 1,
63-
311 => 1,
64-
336 => 1,
65-
361 => 1,
66-
364 => 1,
67-
399 => 1,
68-
403 => 1,
69-
457 => 1,
70-
];
36+
switch ($testFile) {
37+
case 'VariableCommentUnitTest.1.inc':
38+
return [
39+
21 => 1,
40+
24 => 1,
41+
56 => 1,
42+
64 => 1,
43+
73 => 1,
44+
84 => 1,
45+
130 => 1,
46+
136 => 1,
47+
144 => 1,
48+
152 => 1,
49+
160 => 1,
50+
168 => 1,
51+
176 => 1,
52+
184 => 1,
53+
192 => 1,
54+
200 => 1,
55+
208 => 1,
56+
216 => 1,
57+
224 => 1,
58+
232 => 1,
59+
240 => 1,
60+
248 => 1,
61+
256 => 1,
62+
264 => 1,
63+
272 => 1,
64+
280 => 1,
65+
290 => 1,
66+
294 => 1,
67+
311 => 1,
68+
336 => 1,
69+
361 => 1,
70+
364 => 1,
71+
399 => 1,
72+
403 => 1,
73+
457 => 1,
74+
];
75+
76+
case 'VariableCommentUnitTest.2.inc':
77+
return [
78+
8 => 1,
79+
18 => 1,
80+
38 => 1,
81+
48 => 1,
82+
];
83+
84+
default:
85+
return [];
86+
}
7187
}
7288

7389

@@ -77,15 +93,24 @@ public function getErrorList()
7793
* The key of the array should represent the line number and the value
7894
* should represent the number of warnings that should occur on that line.
7995
*
96+
* @param string $testFile The name of the test file being tested.
97+
*
8098
* @return array<int, int>
8199
*/
82-
public function getWarningList()
100+
public function getWarningList($testFile = '')
83101
{
84-
return [
85-
93 => 1,
86-
494 => 1,
87-
495 => 1,
88-
496 => 1,
89-
];
102+
switch ($testFile) {
103+
case 'VariableCommentUnitTest.1.inc':
104+
105+
return [
106+
93 => 1,
107+
494 => 1,
108+
495 => 1,
109+
496 => 1,
110+
];
111+
112+
default:
113+
return [];
114+
}
90115
}
91116
}

tests/Core/Util/Common/SuggestTypeTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,4 +213,34 @@ public static function dataSuggestTypeOther()
213213
],
214214
];
215215
}
216+
217+
218+
/**
219+
* Test the suggestType() for suggesting long types.
220+
*
221+
* @return void
222+
*/
223+
public function testSuggestLongType()
224+
{
225+
$this->assertSame('boolean', Common::suggestType('bool', false));
226+
$this->assertSame('boolean', Common::suggestType('boolean', false));
227+
228+
$this->assertSame('integer', Common::suggestType('int', false));
229+
$this->assertSame('integer', Common::suggestType('integer', false));
230+
}
231+
232+
233+
/**
234+
* Test the suggestType() for suggesting short types.
235+
*
236+
* @return void
237+
*/
238+
public function testSuggestShortType()
239+
{
240+
$this->assertSame('bool', Common::suggestType('bool', true));
241+
$this->assertSame('bool', Common::suggestType('boolean', true));
242+
243+
$this->assertSame('int', Common::suggestType('int', true));
244+
$this->assertSame('int', Common::suggestType('integer', true));
245+
}
216246
}

0 commit comments

Comments
 (0)