1- <?php 
2- use  PHPUnit \Framework \TestCase ;
3- 
4- /** 
5-  * Indentation tests. 
6-  */ 
7- class  IndentationTest extends  TestCase {
8- 
9- 	/** 
10- 	 * Test tabs indentation. 
11- 	 */ 
12- 	public  function  testTabIndentation () {
13- 		$ phpcheckstyle  = $ GLOBALS  ['PHPCheckstyle ' ];
14- 
15- 		$ phpcheckstyle ->processFiles (array (
16- 			'./test/sample/bad_indentation.php ' 
17- 		));
18- 
19- 		$ errorCounts  = $ phpcheckstyle ->getErrorCounts ();
20- 
21- 		$ this  ->assertEquals (0 , $ errorCounts ['error ' ], 'We expect 0 errors ' );
22- 		$ this  ->assertEquals (0 , $ errorCounts ['ignore ' ], 'We expect 0 ignored checks ' );
23- 		$ this  ->assertEquals (0 , $ errorCounts ['info ' ], 'We expect 0 info ' );
24- 		$ this  ->assertEquals (6 , $ errorCounts ['warning ' ], 'We expect 6 warnings ' );
25- 	}
26- 
27- 	/** 
28- 	 * Test tabs indentation. 
29- 	 */ 
30- 	public  function  testSpaceIndentation () {
31- 		$ phpcheckstyle  = $ GLOBALS  ['PHPCheckstyle ' ];
32- 
33- 		// Change the configuration to check for spaces instead of tabs 
34- 		$ phpcheckstyle ->getConfig ()->setTestProperty ('indentation ' , 'type ' , 'spaces ' );
35- 
36- 		$ phpcheckstyle ->processFiles (array (
37- 			'./test/sample/bad_indentation.php ' 
38- 		));
39- 
40- 		$ errorCounts  = $ phpcheckstyle ->getErrorCounts ();
41- 
42- 		$ this  ->assertEquals (0 , $ errorCounts ['error ' ], 'We expect 0 errors ' );
43- 		$ this  ->assertEquals (0 , $ errorCounts ['ignore ' ], 'We expect 0 ignored checks ' );
44- 		$ this  ->assertEquals (0 , $ errorCounts ['info ' ], 'We expect 0 info ' );
45- 		$ this  ->assertEquals (11 , $ errorCounts ['warning ' ], 'We expect 11 warnings ' );
46- 	}
47- 
48- 	/** 
49- 	 * Test tabs indentation. 
50- 	 */ 
51- 	public  function  testSpaceIndentationArray () {
52- 		$ phpcheckstyle  = $ GLOBALS  ['PHPCheckstyle ' ];
53- 
54- 		// Change the configuration to check for spaces instead of tabs 
55- 		$ phpcheckstyle ->getConfig ()->setTestProperty ('indentation ' , 'type ' , 'spaces ' );
56- 
57- 		$ phpcheckstyle ->processFiles (array (
58- 			'./test/sample/bad_indentation_array.php ' 
59- 		));
60- 
61- 		$ errorCounts  = $ phpcheckstyle ->getErrorCounts ();
62- 
63- 		$ this  ->assertEquals (0 , $ errorCounts ['error ' ], 'We expect 0 errors ' );
64- 		$ this  ->assertEquals (0 , $ errorCounts ['ignore ' ], 'We expect 0 ignored checks ' );
65- 		$ this  ->assertEquals (0 , $ errorCounts ['info ' ], 'We expect 0 info ' );
66- 		$ this  ->assertEquals (11 , $ errorCounts ['warning ' ], 'We expect 11 warnings ' );
67- 	}
68- 
69- 	/** 
70- 	 * Test tabs indentation. 
71- 	 */ 
72- 	public  function  testGoodSpaceIndentationArray () {
73- 		$ phpcheckstyle  = $ GLOBALS  ['PHPCheckstyle ' ];
74- 
75- 		// Change the configuration to check for spaces instead of tabs 
76- 		$ phpcheckstyle ->getConfig ()->setTestProperty ('indentation ' , 'type ' , 'spaces ' );
77- 
78- 		$ phpcheckstyle ->processFiles (array (
79- 			'./test/sample/good_indentation_array.php ' 
80- 		));
81- 
82- 		$ errorCounts  = $ phpcheckstyle ->getErrorCounts ();
83- 
84- 		$ this  ->assertEquals (0 , $ errorCounts ['error ' ], 'We expect 0 errors ' );
85- 		$ this  ->assertEquals (0 , $ errorCounts ['ignore ' ], 'We expect 0 ignored checks ' );
86- 		$ this  ->assertEquals (0 , $ errorCounts ['info ' ], 'We expect 0 info ' );
87- 		$ this  ->assertEquals (0 , $ errorCounts ['warning ' ], 'We expect 0 warnings ' );
88- 	}
89- 
90- 	/** 
91- 	 * Test for indentation with new line indentation. 
92- 	 */ 
93- 	public  function  testGoodIndentationNewLine () {
94- 		$ phpcheckstyle  = $ GLOBALS  ['PHPCheckstyle ' ];
95- 
96- 		// Change the configuration to check for spaces instead of tabs 
97- 		$ phpcheckstyle ->getConfig ()->setTestProperty ('controlStructOpenCurly ' , 'position ' , 'nl ' );
98- 		$ phpcheckstyle ->getConfig ()->setTestProperty ('funcDefinitionOpenCurly ' , 'position ' , 'nl ' );
99- 		$ phpcheckstyle ->getConfig ()->setTestProperty ('controlStructElse ' , 'position ' , 'nl ' );
100- 
101- 
102- 		$ phpcheckstyle ->processFiles (array (
103- 			'./test/sample/good_indentation_newline.php ' 
104- 		));
105- 
106- 		$ errorCounts  = $ phpcheckstyle ->getErrorCounts ();
107- 
108- 		$ this  ->assertEquals (0 , $ errorCounts ['error ' ], 'We expect 0 errors ' );
109- 		$ this  ->assertEquals (0 , $ errorCounts ['ignore ' ], 'We expect 0 ignored checks ' );
110- 		$ this  ->assertEquals (0 , $ errorCounts ['info ' ], 'We expect 0 info ' );
111- 		$ this  ->assertEquals (0 , $ errorCounts ['warning ' ], 'We expect 0 warnings ' );
112- 	}
113- 
114- 	/** 
115- 	 * Test for indentation with spaces. 
116- 	 */ 
117- 	public  function  testGoodIndentationSpaces () {
118- 		$ phpcheckstyle  = $ GLOBALS  ['PHPCheckstyle ' ];
119- 
120- 		// Change the configuration to check for spaces instead of tabs 
121- 		$ phpcheckstyle ->getConfig ()->setTestProperty ('indentation ' , 'type ' , 'spaces ' );
122- 
123- 		$ phpcheckstyle ->processFiles (array (
124- 			'./test/sample/good_indentation_space.php ' 
125- 		));
126- 
127- 		$ errorCounts  = $ phpcheckstyle ->getErrorCounts ();
128- 
129- 		$ this  ->assertEquals (0 , $ errorCounts ['error ' ], 'We expect 0 errors ' );
130- 		$ this  ->assertEquals (0 , $ errorCounts ['ignore ' ], 'We expect 0 ignored checks ' );
131- 		$ this  ->assertEquals (0 , $ errorCounts ['info ' ], 'We expect 0 info ' );
132- 		$ this  ->assertEquals (0 , $ errorCounts ['warning ' ], 'We expect 0 warnings ' );
133- 	}
134- 
135- 
136- 	/** 
137- 	 * Test for for spaces missing or in excedent. 
138- 	 */ 
139- 	public  function  testBadSpaces () {
140- 		$ phpcheckstyle  = $ GLOBALS  ['PHPCheckstyle ' ];
141- 
142- 		$ phpcheckstyle ->processFiles (array (
143- 			'./test/sample/bad_spaces.php ' 
144- 		));
145- 
146- 		$ errorCounts  = $ phpcheckstyle ->getErrorCounts ();
147- 
148- 		$ this  ->assertEquals (0 , $ errorCounts ['error ' ], 'We expect 0 errors of naming ' );
149- 		$ this  ->assertEquals (0 , $ errorCounts ['ignore ' ], 'We expect 0 ignored checks ' );
150- 		$ this  ->assertEquals (2 , $ errorCounts ['info ' ], 'We expect 2 info ' );
151- 		$ this  ->assertEquals (7 , $ errorCounts ['warning ' ], 'We expect 7 warnings ' );
152- 	}
153- }
1+ <?php 
2+ use  PHPUnit \Framework \TestCase ;
3+ 
4+ /** 
5+  * Indentation tests. 
6+  */ 
7+ class  IndentationTest extends  TestCase {
8+ 
9+ 	/** 
10+ 	 * Test tabs indentation. 
11+ 	 */ 
12+ 	public  function  testTabIndentation () {
13+ 		$ phpcheckstyle  = $ GLOBALS  ['PHPCheckstyle ' ];
14+ 
15+ 		$ phpcheckstyle ->processFiles (array (
16+ 			'./test/sample/bad_indentation.php ' 
17+ 		));
18+ 
19+ 		$ errorCounts  = $ phpcheckstyle ->getErrorCounts ();
20+ 
21+ 		$ this  ->assertEquals (0 , $ errorCounts ['error ' ], 'We expect 0 errors ' );
22+ 		$ this  ->assertEquals (0 , $ errorCounts ['ignore ' ], 'We expect 0 ignored checks ' );
23+ 		$ this  ->assertEquals (0 , $ errorCounts ['info ' ], 'We expect 0 info ' );
24+ 		$ this  ->assertEquals (6 , $ errorCounts ['warning ' ], 'We expect 6 warnings ' );
25+ 	}
26+ 
27+ 	/** 
28+ 	 * Test tabs indentation. 
29+ 	 */ 
30+ 	public  function  testSpaceIndentation () {
31+ 		$ phpcheckstyle  = $ GLOBALS  ['PHPCheckstyle ' ];
32+ 
33+ 		// Change the configuration to check for spaces instead of tabs 
34+ 		$ phpcheckstyle ->getConfig ()->setTestProperty ('indentation ' , 'type ' , 'spaces ' );
35+ 
36+ 		$ phpcheckstyle ->processFiles (array (
37+ 			'./test/sample/bad_indentation.php ' 
38+ 		));
39+ 
40+ 		$ errorCounts  = $ phpcheckstyle ->getErrorCounts ();
41+ 
42+ 		$ this  ->assertEquals (0 , $ errorCounts ['error ' ], 'We expect 0 errors ' );
43+ 		$ this  ->assertEquals (0 , $ errorCounts ['ignore ' ], 'We expect 0 ignored checks ' );
44+ 		$ this  ->assertEquals (0 , $ errorCounts ['info ' ], 'We expect 0 info ' );
45+ 		$ this  ->assertEquals (11 , $ errorCounts ['warning ' ], 'We expect 11 warnings ' );
46+ 	}
47+ 
48+ 	/** 
49+ 	 * Test tabs indentation. 
50+ 	 */ 
51+ 	public  function  testSpaceIndentationArray () {
52+ 		$ phpcheckstyle  = $ GLOBALS  ['PHPCheckstyle ' ];
53+ 
54+ 		// Change the configuration to check for spaces instead of tabs 
55+ 		$ phpcheckstyle ->getConfig ()->setTestProperty ('indentation ' , 'type ' , 'spaces ' );
56+ 
57+ 		$ phpcheckstyle ->processFiles (array (
58+ 			'./test/sample/bad_indentation_array.php ' 
59+ 		));
60+ 
61+ 		$ errorCounts  = $ phpcheckstyle ->getErrorCounts ();
62+ 
63+ 		$ this  ->assertEquals (0 , $ errorCounts ['error ' ], 'We expect 0 errors ' );
64+ 		$ this  ->assertEquals (0 , $ errorCounts ['ignore ' ], 'We expect 0 ignored checks ' );
65+ 		$ this  ->assertEquals (0 , $ errorCounts ['info ' ], 'We expect 0 info ' );
66+ 		$ this  ->assertEquals (11 , $ errorCounts ['warning ' ], 'We expect 11 warnings ' );
67+ 	}
68+ 
69+ 	/** 
70+ 	 * Test tabs indentation. 
71+ 	 */ 
72+ 	public  function  testGoodSpaceIndentationArray () {
73+ 		$ phpcheckstyle  = $ GLOBALS  ['PHPCheckstyle ' ];
74+ 
75+ 		// Change the configuration to check for spaces instead of tabs 
76+ 		$ phpcheckstyle ->getConfig ()->setTestProperty ('indentation ' , 'type ' , 'spaces ' );
77+ 
78+ 		$ phpcheckstyle ->processFiles (array (
79+ 			'./test/sample/good_indentation_array.php ' 
80+ 		));
81+ 
82+ 		$ errorCounts  = $ phpcheckstyle ->getErrorCounts ();
83+ 
84+ 		$ this  ->assertEquals (0 , $ errorCounts ['error ' ], 'We expect 0 errors ' );
85+ 		$ this  ->assertEquals (0 , $ errorCounts ['ignore ' ], 'We expect 0 ignored checks ' );
86+ 		$ this  ->assertEquals (0 , $ errorCounts ['info ' ], 'We expect 0 info ' );
87+ 		$ this  ->assertEquals (0 , $ errorCounts ['warning ' ], 'We expect 0 warnings ' );
88+ 	}
89+ 
90+ 	/** 
91+ 	 * Test for indentation with new line indentation. 
92+ 	 */ 
93+ 	public  function  testGoodIndentationNewLine () {
94+ 		$ phpcheckstyle  = $ GLOBALS  ['PHPCheckstyle ' ];
95+ 
96+ 		// Change the configuration to check for spaces instead of tabs 
97+ 		$ phpcheckstyle ->getConfig ()->setTestProperty ('controlStructOpenCurly ' , 'position ' , 'nl ' );
98+ 		$ phpcheckstyle ->getConfig ()->setTestProperty ('funcDefinitionOpenCurly ' , 'position ' , 'nl ' );
99+ 		$ phpcheckstyle ->getConfig ()->setTestProperty ('controlStructElse ' , 'position ' , 'nl ' );
100+ 
101+ 		$ phpcheckstyle ->processFiles (array (
102+ 			'./test/sample/good_indentation_newline.php ' 
103+ 		));
104+ 
105+ 		$ errorCounts  = $ phpcheckstyle ->getErrorCounts ();
106+ 
107+ 		$ this  ->assertEquals (0 , $ errorCounts ['error ' ], 'We expect 0 errors ' );
108+ 		$ this  ->assertEquals (0 , $ errorCounts ['ignore ' ], 'We expect 0 ignored checks ' );
109+ 		$ this  ->assertEquals (0 , $ errorCounts ['info ' ], 'We expect 0 info ' );
110+ 		$ this  ->assertEquals (0 , $ errorCounts ['warning ' ], 'We expect 0 warnings ' );
111+ 	}
112+ 
113+ 	/** 
114+ 	 * Test for indentation with spaces. 
115+ 	 */ 
116+ 	public  function  testGoodIndentationSpaces () {
117+ 		$ phpcheckstyle  = $ GLOBALS  ['PHPCheckstyle ' ];
118+ 
119+ 		// Change the configuration to check for spaces instead of tabs 
120+ 		$ phpcheckstyle ->getConfig ()->setTestProperty ('indentation ' , 'type ' , 'spaces ' );
121+ 
122+ 		$ phpcheckstyle ->processFiles (array (
123+ 			'./test/sample/good_indentation_space.php ' 
124+ 		));
125+ 
126+ 		$ errorCounts  = $ phpcheckstyle ->getErrorCounts ();
127+ 
128+ 		$ this  ->assertEquals (0 , $ errorCounts ['error ' ], 'We expect 0 errors ' );
129+ 		$ this  ->assertEquals (0 , $ errorCounts ['ignore ' ], 'We expect 0 ignored checks ' );
130+ 		$ this  ->assertEquals (0 , $ errorCounts ['info ' ], 'We expect 0 info ' );
131+ 		$ this  ->assertEquals (0 , $ errorCounts ['warning ' ], 'We expect 0 warnings ' );
132+ 	}
133+ 
134+ 	/** 
135+ 	 * Test for for spaces missing or in excedent. 
136+ 	 */ 
137+ 	public  function  testBadSpaces () {
138+ 		$ phpcheckstyle  = $ GLOBALS  ['PHPCheckstyle ' ];
139+ 
140+ 		$ phpcheckstyle ->processFiles (array (
141+ 			'./test/sample/bad_spaces.php ' 
142+ 		));
143+ 
144+ 		$ errorCounts  = $ phpcheckstyle ->getErrorCounts ();
145+ 
146+ 		$ this  ->assertEquals (0 , $ errorCounts ['error ' ], 'We expect 0 errors of naming ' );
147+ 		$ this  ->assertEquals (0 , $ errorCounts ['ignore ' ], 'We expect 0 ignored checks ' );
148+ 		$ this  ->assertEquals (2 , $ errorCounts ['info ' ], 'We expect 2 info ' );
149+ 		$ this  ->assertEquals (7 , $ errorCounts ['warning ' ], 'We expect 7 warnings ' );
150+ 	}
151+ 
152+ 	/** 
153+ 	 * Test for space after control statement (no space after control statement). 
154+ 	 */ 
155+ 	public  function  testBadSpaceAfterControl () {
156+ 		$ phpcheckstyle  = $ GLOBALS  ['PHPCheckstyle ' ];
157+ 
158+ 		// Change the configuration to check for spaces instead of tabs 
159+ 		$ phpcheckstyle ->getConfig ()->setTestProperty ('spaceaftercontrolstmt ' , 'type ' , 'spaces ' );
160+ 
161+ 		// Change the configuration to check for no spaces after control statement 
162+ 		$ config  = $ phpcheckstyle ->getConfig ();
163+ 		$ refl  = new  \ReflectionProperty ($ config , 'config ' );
164+ 		$ refl ->setAccessible (true );
165+ 		$ value  = $ refl ->getValue ($ config );
166+ 		unset($ value ['spaceaftercontrolstmt ' ]);
167+ 		$ value ['nospaceaftercontrolstmt ' ] = array ();
168+ 		$ refl ->setValue ($ config , $ value );
169+ 
170+ 		$ phpcheckstyle ->processFiles (array (
171+ 			'./test/sample/bad_space_after_control.php ' 
172+ 		));
173+ 
174+ 		$ errorCounts  = $ phpcheckstyle ->getErrorCounts ();
175+ 
176+ 		$ this  ->assertEquals (0 , $ errorCounts ['error ' ], 'We expect 0 errors ' );
177+ 		$ this  ->assertEquals (0 , $ errorCounts ['ignore ' ], 'We expect 0 ignored checks ' );
178+ 		$ this  ->assertEquals (0 , $ errorCounts ['info ' ], 'We expect 0 info ' );
179+ 		$ this  ->assertEquals (1 , $ errorCounts ['warning ' ], 'We expect 1 warning ' );
180+ 	}
181+ }
154182?> 
0 commit comments