@@ -34,7 +34,7 @@ protected function setUp(): void
3434 $ this ->fs ->dumpFile ($ this ->pluginDir . '/.moodle-plugin-ci.yml ' , Yaml::dump ($ config ));
3535 }
3636
37- protected function executeCommand ($ pluginDir = null , $ maxWarnings = - 1 , $ testVersion = null ): CommandTester
37+ protected function executeCommand ($ pluginDir = null , array $ options = [] ): CommandTester
3838 {
3939 if ($ pluginDir === null ) {
4040 $ pluginDir = $ this ->pluginDir ;
@@ -46,14 +46,7 @@ protected function executeCommand($pluginDir = null, $maxWarnings = -1, $testVer
4646 $ application = new Application ();
4747 $ application ->add ($ command );
4848
49- $ options = ['plugin ' => $ pluginDir ];
50- if ($ maxWarnings >= 0 ) {
51- $ options ['--max-warnings ' ] = $ maxWarnings ;
52- }
53-
54- if (null !== $ testVersion ) {
55- $ options ['--test-version ' ] = $ testVersion ;
56- }
49+ $ options = array_merge (['plugin ' => $ pluginDir ], $ options );
5750
5851 $ commandTester = new CommandTester ($ application ->find ('codechecker ' ));
5952 $ commandTester ->execute ($ options );
@@ -133,19 +126,19 @@ public function testExecuteWithWarningsAndThreshold()
133126 $ this ->assertSame (0 , $ commandTester ->getStatusCode ());
134127
135128 // Allowing 0 warning, it fails.
136- $ commandTester = $ this ->executeCommand ($ this ->pluginDir , 0 );
129+ $ commandTester = $ this ->executeCommand ($ this ->pluginDir , [ ' --max-warnings ' => 0 ] );
137130 $ this ->assertSame (1 , $ commandTester ->getStatusCode ());
138131
139132 // Allowing 1 warning, it fails.
140- $ commandTester = $ this ->executeCommand ($ this ->pluginDir , 1 );
133+ $ commandTester = $ this ->executeCommand ($ this ->pluginDir , [ ' --max-warnings ' => 1 ] );
141134 $ this ->assertSame (1 , $ commandTester ->getStatusCode ());
142135
143136 // Allowing 2 warnings, it passes.
144- $ commandTester = $ this ->executeCommand ($ this ->pluginDir , 2 );
137+ $ commandTester = $ this ->executeCommand ($ this ->pluginDir , [ ' --max-warnings ' => 2 ] );
145138 $ this ->assertSame (0 , $ commandTester ->getStatusCode ());
146139
147140 // Allowing 3 warnings, it passes.
148- $ commandTester = $ this ->executeCommand ($ this ->pluginDir , 3 );
141+ $ commandTester = $ this ->executeCommand ($ this ->pluginDir , [ ' --max-warnings ' => 3 ] );
149142 $ this ->assertSame (0 , $ commandTester ->getStatusCode ());
150143 }
151144
@@ -167,48 +160,66 @@ public function testExecuteWithTestVersion()
167160 $ this ->fs ->dumpFile ($ this ->pluginDir . '/test_versions.php ' , $ content );
168161
169162 // By default, without specify test-version, only reports deprecation warnings and returns 0.
170- $ commandTester = $ this ->executeCommand ($ this ->pluginDir , - 1 , null );
163+ $ commandTester = $ this ->executeCommand ($ this ->pluginDir );
171164 $ output = $ commandTester ->getDisplay ();
172165 $ this ->assertSame (0 , $ commandTester ->getStatusCode ());
173166 $ this ->assertMatchesRegularExpression ('/FOUND 0 ERRORS AND 4 WARNINGS AFFECTING 4 LINES/ ' , $ output );
174167
175168 // With test-version 7.4, reports 3 new errors and <= 7.4 specific warnings and returns 1.
176- $ commandTester = $ this ->executeCommand ($ this ->pluginDir , - 1 , '7.4 ' );
169+ $ commandTester = $ this ->executeCommand ($ this ->pluginDir , [ ' --test-version ' => '7.4 ' ] );
177170 $ output = $ commandTester ->getDisplay ();
178171 $ this ->assertSame (1 , $ commandTester ->getStatusCode ());
179172 $ this ->assertMatchesRegularExpression ('/FOUND 3 ERRORS AND 1 WARNING AFFECTING 4 LINES/ ' , $ output );
180173
181174 // With test-version 8.0, reports 2 new errors and <= 8.0 specific warnings and returns 1.
182- $ commandTester = $ this ->executeCommand ($ this ->pluginDir , - 1 , '8.0 ' );
175+ $ commandTester = $ this ->executeCommand ($ this ->pluginDir , [ ' --test-version ' => '8.0 ' ] );
183176 $ output = $ commandTester ->getDisplay ();
184177 $ this ->assertSame (1 , $ commandTester ->getStatusCode ());
185178 $ this ->assertMatchesRegularExpression ('/FOUND 2 ERRORS AND 2 WARNINGS AFFECTING 4 LINES/ ' , $ output );
186179
187180 // With test-version 8.1, reports 1 new errors and <= 8.1 specific warnings and returns 0.
188- $ commandTester = $ this ->executeCommand ($ this ->pluginDir , - 1 , '8.1 ' );
181+ $ commandTester = $ this ->executeCommand ($ this ->pluginDir , [ ' --test-version ' => '8.1 ' ] );
189182 $ output = $ commandTester ->getDisplay ();
190183 $ this ->assertSame (1 , $ commandTester ->getStatusCode ());
191184 $ this ->assertMatchesRegularExpression ('/FOUND 1 ERROR AND 3 WARNINGS AFFECTING 4 LINES/ ' , $ output );
192185
193186 // With test-version 7.4-8.0, reports 3 new errors and <= 8.0 specific warnings and returns 1.
194- $ commandTester = $ this ->executeCommand ($ this ->pluginDir , - 1 , '7.4-8.0 ' );
187+ $ commandTester = $ this ->executeCommand ($ this ->pluginDir , [ ' --test-version ' => '7.4-8.0 ' ] );
195188 $ output = $ commandTester ->getDisplay ();
196189 $ this ->assertSame (1 , $ commandTester ->getStatusCode ());
197190 $ this ->assertMatchesRegularExpression ('/FOUND 3 ERRORS AND 2 WARNINGS AFFECTING 5 LINES/ ' , $ output );
198191
199192 // With test-version 7.4-8.1, reports 3 new errors and <= 8.1 specific warnings and returns 1.
200- $ commandTester = $ this ->executeCommand ($ this ->pluginDir , - 1 , '7.4-8.1 ' );
193+ $ commandTester = $ this ->executeCommand ($ this ->pluginDir , [ ' --test-version ' => '7.4-8.1 ' ] );
201194 $ output = $ commandTester ->getDisplay ();
202195 $ this ->assertSame (1 , $ commandTester ->getStatusCode ());
203196 $ this ->assertMatchesRegularExpression ('/FOUND 3 ERRORS AND 3 WARNINGS AFFECTING 6 LINES/ ' , $ output );
204197
205198 // With test-version 7.4- (open range), reports 3 new errors and <= 8.2 specific warnings and returns 1.
206- $ commandTester = $ this ->executeCommand ($ this ->pluginDir , - 1 , '7.4- ' );
199+ $ commandTester = $ this ->executeCommand ($ this ->pluginDir , [ ' --test-version ' => '7.4- ' ] );
207200 $ output = $ commandTester ->getDisplay ();
208201 $ this ->assertSame (1 , $ commandTester ->getStatusCode ());
209202 $ this ->assertMatchesRegularExpression ('/FOUND 3 ERRORS AND 4 WARNINGS AFFECTING 7 LINES/ ' , $ output );
210203 }
211204
205+ public function testExecuteWithExclusions ()
206+ {
207+ // Add a file with errors and warnings, and verify that they are suppressed with the exclusions.
208+ $ content = "<?php require(__DIR__.'/../../config.php'); \n" ;
209+
210+ $ this ->fs ->dumpFile ($ this ->pluginDir . '/warnings.php ' , $ content );
211+
212+ // Without exclusions.
213+ $ commandTester = $ this ->executeCommand ($ this ->pluginDir );
214+ $ output = $ commandTester ->getDisplay ();
215+ $ this ->assertSame (1 , $ commandTester ->getStatusCode ());
216+ $ this ->assertMatchesRegularExpression ('/FOUND 9 ERRORS AND 1 WARNING AFFECTING 1 LINE/ ' , $ output );
217+
218+ // With exclusions.
219+ $ commandTester = $ this ->executeCommand ($ this ->pluginDir , ['--exclude ' => 'moodle.Files.RequireLogin,moodle.Files.BoilerplateComment ' ]);
220+ $ this ->assertSame (0 , $ commandTester ->getStatusCode ());
221+ }
222+
212223 public function testExecuteNoFiles ()
213224 {
214225 // Just random directory with no PHP files.
0 commit comments