Skip to content

Commit 1b57d79

Browse files
committed
Use annotations in fixture files
It seems that the ruleset.xml properties aren't processed anymore when running individual Sniffs under testing. That may have sense, so we are able to cover all different behaviours instead of just covering the standard one. So it's assumed that it's a correct feature. So, now, we have to slightly modify our fixture files to add phpcs: annotations to explicitly say which properties to use when running the tests. They should match 100% the ruleset.xml ones. I've created squizlabs/PHP_CodeSniffer#3128 to ask if that's intended or no.
1 parent 3f37daa commit 1b57d79

File tree

5 files changed

+59
-49
lines changed

5 files changed

+59
-49
lines changed

moodle/ruleset.xml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@
2828
<rule ref="Generic.PHP.DisallowShortOpenTag"/>
2929
<rule ref="Generic.PHP.LowerCaseConstant"/>
3030

31-
<rule ref="Generic.WhiteSpace.ScopeIndent"/>
31+
<rule ref="Generic.WhiteSpace.ScopeIndent">
32+
<properties>
33+
<property name="ignoreIndentationTokens" type="array"
34+
value="T_CLOSE_TAG"/>
35+
</properties>
36+
</rule>
3237
<rule ref="Generic.WhiteSpace.DisallowTabIndent"/>
3338

3439
<rule ref="Squiz.Classes.DuplicateProperty"/>
@@ -63,7 +68,9 @@
6368
</properties>
6469
</rule>
6570
<rule ref="Squiz.WhiteSpace.ObjectOperatorSpacing">
66-
<exclude name="Squiz.WhiteSpace.ObjectOperatorSpacing.Before"/>
71+
<properties>
72+
<property name="ignoreNewlines" value="true"/>
73+
</properties>
6774
</rule>
6875
<rule ref="PEAR.WhiteSpace.ObjectOperatorIndent"/>
6976
<rule ref="Squiz.WhiteSpace.ScopeClosingBrace"/>

moodle/tests/fixtures/generic_whitespace_scopeindent.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
phpcs:set Generic.WhiteSpace.ScopeIndent ignoreIndentationTokens[] T_CLOSE_TAG
12
<?php
23
defined('MOODLE_INTERNAL') || die(); // Make this always the 1st line in all CS fixtures.
34

@@ -46,7 +47,7 @@
4647
echo "this is OK too";
4748
}
4849
}
49-
// The close tag must be aligned, hence next one fails.
50+
// There is freedom for closing tags, it's not clear the policy to follow when mixing multiple sections.
5051
?>
5152
// Adding some known content that caused problems. See CONTRIB-6146.
5253
// Source: https://github.com/roelmann/moodle-theme_flexibase/blob/d99ca95f0b77c4cd2f877cf8b1d0715acb392cf4/layout/secure.php

moodle/tests/fixtures/squiz_whitespace_objectoperatorspacing.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
phpcs:set Squiz.WhiteSpace.ObjectOperatorSpacing ignoreNewlines true
12
<?php
23
defined('MOODLE_INTERNAL') || die(); // Make this always the 1st line in all CS fixtures.
34

moodle/tests/fixtures/squiz_whitespace_operatorspacing.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
phpcs:set Squiz.WhiteSpace.OperatorSpacing ignoreNewlines true
12
<?php
23
defined('MOODLE_INTERNAL') || die(); // Make this always the 1st line in all CS fixtures.
34

moodle/tests/moodlestandard_test.php

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,10 @@ public function test_generic_whitespace_scopeindent() {
219219
// - line => array of contents for message / source problem matching.
220220
// - line => string of contents for message / source problem matching (only 1).
221221
$this->set_errors(array(
222-
6 => 'indented incorrectly; expected at least 4 spaces, found 2 @Source: Generic.WhiteSpace.ScopeIndent.Incorrect',
223-
18 => 'indented incorrectly; expected at least 4 spaces, found 2 @Source: Generic.WhiteSpace.ScopeIndent.Incorrect',
224-
43 => 'expected at least 8 spaces',
225-
50 => 'IncorrectExact'));
222+
7 => 'indented incorrectly; expected at least 4 spaces, found 2 @Source: Generic.WhiteSpace.ScopeIndent.Incorrect',
223+
19 => 'indented incorrectly; expected at least 4 spaces, found 2 @Source: Generic.WhiteSpace.ScopeIndent.Incorrect',
224+
44 => 'expected at least 8 spaces',
225+
));
226226
$this->set_warnings(array());
227227

228228
// Let's do all the hard work!
@@ -492,50 +492,49 @@ public function test_squiz_operator_spacing() {
492492
// - line => array of contents for message / source problem matching.
493493
// - line => string of contents for message / source problem matching (only 1).
494494
$this->set_errors(array(
495-
5 => 0,
496-
6 => 'Expected 1 space before',
497-
7 => 'Expected 1 space after',
498-
8 => array('Expected 1 space before', 'Expected 1 space after'),
499-
9 => 0,
500-
10 => 'Expected 1 space after "=>"; 3 found',
501-
11 => 0,
495+
6 => 0,
496+
7 => 'Expected 1 space before',
497+
8 => 'Expected 1 space after',
498+
9 => array('Expected 1 space before', 'Expected 1 space after'),
499+
10 => 0,
500+
11 => 'Expected 1 space after "=>"; 3 found',
502501
12 => 0,
503-
13 => 'Expected 1 space before',
504-
14 => 'Expected 1 space after',
505-
15 => array('Expected 1 space before', 'Expected 1 space after'),
506-
16 => 0,
507-
17 => 'Expected 1 space after "="; 2 found',
508-
18 => 0,
502+
13 => 0,
503+
14 => 'Expected 1 space before',
504+
15 => 'Expected 1 space after',
505+
16 => array('Expected 1 space before', 'Expected 1 space after'),
506+
17 => 0,
507+
18 => 'Expected 1 space after "="; 2 found',
509508
19 => 0,
510509
20 => 0,
511-
21 => 'Expected 1 space before',
512-
22 => 'Expected 1 space after',
513-
23 => array('Expected 1 space before', 'Expected 1 space after'),
514-
24 => 0,
515-
25 => 'Expected 1 space after "+"; 2 found',
516-
26 => 'Expected 1 space before "+"; 2 found',
517-
27 => 0,
518-
28 => 'Expected 1 space before',
519-
29 => 'Expected 1 space after',
520-
30 => array('Expected 1 space before', 'Expected 1 space after'),
521-
31 => 0,
522-
32 => 'Expected 1 space after "-"; 2 found',
523-
33 => 'Expected 1 space before "-"; 2 found',
524-
34 => 0,
525-
35 => 'Expected 1 space before',
526-
36 => 'Expected 1 space after',
527-
37 => array('Expected 1 space before', 'Expected 1 space after'),
528-
38 => 0,
529-
39 => 'Expected 1 space after "*"; 2 found',
530-
40 => 'Expected 1 space before "*"; 2 found',
531-
41 => 0,
532-
42 => 'Expected 1 space before',
533-
43 => 'Expected 1 space after',
534-
44 => array('Expected 1 space before', 'Expected 1 space after'),
535-
45 => 0,
536-
46 => 'Expected 1 space after "/"; 2 found',
537-
47 => 'Expected 1 space before "/"; 2 found',
538-
48 => 0,
510+
21 => 0,
511+
22 => 'Expected 1 space before',
512+
23 => 'Expected 1 space after',
513+
24 => array('Expected 1 space before', 'Expected 1 space after'),
514+
25 => 0,
515+
26 => 'Expected 1 space after "+"; 2 found',
516+
27 => 'Expected 1 space before "+"; 2 found',
517+
28 => 0,
518+
29 => 'Expected 1 space before',
519+
30 => 'Expected 1 space after',
520+
31 => array('Expected 1 space before', 'Expected 1 space after'),
521+
32 => 0,
522+
33 => 'Expected 1 space after "-"; 2 found',
523+
34 => 'Expected 1 space before "-"; 2 found',
524+
35 => 0,
525+
36 => 'Expected 1 space before',
526+
37 => 'Expected 1 space after',
527+
38 => array('Expected 1 space before', 'Expected 1 space after'),
528+
39 => 0,
529+
40 => 'Expected 1 space after "*"; 2 found',
530+
41 => 'Expected 1 space before "*"; 2 found',
531+
42 => 0,
532+
43 => 'Expected 1 space before',
533+
44 => 'Expected 1 space after',
534+
45 => array('Expected 1 space before', 'Expected 1 space after'),
535+
46 => 0,
536+
47 => 'Expected 1 space after "/"; 2 found',
537+
48 => 'Expected 1 space before "/"; 2 found',
539538
49 => 0,
540539
50 => 0,
541540
51 => 0,
@@ -549,7 +548,8 @@ public function test_squiz_operator_spacing() {
549548
59 => 0,
550549
60 => 0,
551550
61 => 0,
552-
62 => 0
551+
62 => 0,
552+
63 => 0
553553
));
554554
$this->set_warnings(array());
555555

0 commit comments

Comments
 (0)