@@ -96,13 +96,19 @@ abstract private function somefunc() { // To verify PHPCompatibility sniff.
9696 $ output = $ commandTester ->getDisplay ();
9797 $ this ->assertMatchesRegularExpression ('/E\.* 10\.* \/ 10 \(100%\)/ ' , $ output ); // Progress.
9898 $ this ->assertMatchesRegularExpression ('/\/fixable.php/ ' , $ output ); // File.
99- $ this ->assertMatchesRegularExpression ('/ 8 ERRORS AND 1 WARNING AFFECTING 8 / ' , $ output ); // Summary.
99+ $ this ->assertMatchesRegularExpression ('/ 11 ERRORS AND 1 WARNING AFFECTING 8 / ' , $ output ); // Summary.
100100 $ this ->assertMatchesRegularExpression ('/moodle\.Files\.BoilerplateComment\.Wrong/ ' , $ output ); // Moodle sniff.
101+ $ this ->assertMatchesRegularExpression ('/Expected MOODLE_INTERNAL check/ ' , $ output ); // Moodle sniff.
101102 $ this ->assertMatchesRegularExpression ('/print_error\(\) has been deprecated/ ' , $ output ); // Moodle sniff.
103+ $ this ->assertMatchesRegularExpression ('/Usage of ELSEIF not allowed; use ELSE IF/ ' , $ output ); // Squiz sniff.
102104 $ this ->assertMatchesRegularExpression ('/print_object\(\) is forbidden/ ' , $ output ); // Moodle sniff.
103- $ this ->assertMatchesRegularExpression ('/Missing doc comment for class test/ ' , $ output ); // Moodle sniff.
105+ $ this ->assertMatchesRegularExpression ('/Missing docblock for class test/ ' , $ output ); // Moodle sniff.
106+ $ this ->assertMatchesRegularExpression ('/Missing @copyright tag/ ' , $ output ); // Moodle sniff.
107+ $ this ->assertMatchesRegularExpression ('/Missing @license tag/ ' , $ output ); // Moodle sniff.
108+ $ this ->assertMatchesRegularExpression ('/Missing docblock for function somefunc/ ' , $ output ); // Moodle sniff.
104109 $ this ->assertMatchesRegularExpression ('/AbstractPrivateMethods\.Found/ ' , $ output ); // PHPCompatibility sniff.
105- $ this ->assertMatchesRegularExpression ('/Files\.EndFileNewline\.NotFound/ ' , $ output ); // End of file.
110+ $ this ->assertMatchesRegularExpression ('/Opening brace must be the last content/ ' , $ output ); // Generic sniff.
111+ $ this ->assertMatchesRegularExpression ('/Files\.EndFileNewline\.NotFound/ ' , $ output ); // Generic of file.
106112 $ this ->assertMatchesRegularExpression ('/PHPCBF CAN FIX THE 3 MARKED SNIFF/ ' , $ output ); // PHPCBF note.
107113 $ this ->assertMatchesRegularExpression ('/Time:.*Memory:/ ' , $ output ); // Time.
108114
@@ -214,27 +220,38 @@ public function testExecuteWithExclusions()
214220 $ commandTester = $ this ->executeCommand ($ this ->pluginDir );
215221 $ output = $ commandTester ->getDisplay ();
216222 $ this ->assertSame (1 , $ commandTester ->getStatusCode ());
217- $ this ->assertMatchesRegularExpression ('/FOUND 9 ERRORS AND 1 WARNING AFFECTING 1 LINE/ ' , $ output );
223+ $ this ->assertMatchesRegularExpression ('/FOUND \d+ ERRORS? AND \d+ WARNINGS? AFFECTING 1 LINE/ ' , $ output );
218224
219225 // With exclusions.
220- $ commandTester = $ this ->executeCommand ($ this ->pluginDir , ['--exclude ' => 'moodle.Files.RequireLogin,moodle.Files.BoilerplateComment ' ]);
226+ $ commandTester = $ this ->executeCommand (
227+ $ this ->pluginDir ,
228+ ['--exclude ' => 'moodle.Files.RequireLogin, ' .
229+ 'moodle.Files.BoilerplateComment, ' .
230+ 'moodle.Commenting.MissingDocblock, ' .
231+ 'moodle.Commenting.FileExpectedTags ' ]
232+ );
221233 $ this ->assertSame (0 , $ commandTester ->getStatusCode ());
222234 }
223235
224236 public function testExecuteWithTodoCommentRegex ()
225237 {
226- // Let's add a file with some comments having links and some without
238+ // Let's add a file with some comments having links and some without.
227239 $ content = <<<'EOT'
228240 <?php
229241 // phpcs:disable moodle.Files.BoilerplateComment
230- // Without any CUSTOM-[0-9]+ reference.
242+
243+ /**
244+ * This is a nice fixture file with some todo tags.
245+ *
246+ * @copyright 2024 onwards Eloy Lafuente (stronk7) {@link https://stronk7.com}
247+ * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
248+ * @todo This is also the simplest, but within a phpdoc block
249+ * @todo This is also the simplest, but within a phpdoc block. CUSTOM-123
250+ */
231251
232252 // TODO: This is the simplest TODO comment.
233- /** @todo This is also the simplest, but within a phpdoc block */
234- // With a CUSTOM-[0-9]+ reference.
235253
236254 // TODO: This is the simplest TODO comment. CUSTOM-123.
237- /** @todo This is also the simplest, but within a phpdoc block. CUSTOM-123 */
238255
239256 EOT;
240257
@@ -247,13 +264,53 @@ public function testExecuteWithTodoCommentRegex()
247264 $ this ->assertSame (0 , $ commandTester ->getStatusCode ());
248265
249266 // With a "CUSTOM-[0-9]+" regex configured.
267+ // TODO: This will start requiring complete regexp soon, see https://github.com/moodlehq/moodle-cs/issues/141
268+ // (with "complete regex" meaning, with delimiters, basically).
250269 $ commandTester = $ this ->executeCommand ($ this ->pluginDir , ['--todo-comment-regex ' => 'CUSTOM-[0-9]+ ' ]);
251270 $ output = $ commandTester ->getDisplay ();
252271 $ this ->assertSame (0 , $ commandTester ->getStatusCode ());
253272 $ this ->assertMatchesRegularExpression ('/FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES/ ' , $ output );
254273 $ this ->assertMatchesRegularExpression ('/Missing required "CUSTOM-\[0-9\]\+"/ ' , $ output );
255274 }
256275
276+ public function testExecuteWithLicenseRegex ()
277+ {
278+ // Let's add a file with some comments having various licenses.
279+ $ content = <<<'EOT'
280+ <?php
281+ // phpcs:disable moodle.Files.BoilerplateComment
282+
283+ /**
284+ * This is a nice fixture file with some licenses.
285+ *
286+ * @copyright 2024 onwards Eloy Lafuente (stronk7) {@link https://stronk7.com}
287+ * @license https://example.org/invented-license IL v3 or later
288+ */
289+
290+ EOT;
291+
292+ $ this ->fs ->dumpFile ($ this ->pluginDir . '/test_comment_licenses.php ' , $ content );
293+
294+ // Without any regex configured.
295+ $ commandTester = $ this ->executeCommand ($ this ->pluginDir );
296+ $ output = $ commandTester ->getDisplay ();
297+ $ this ->assertSame (0 , $ commandTester ->getStatusCode ());
298+ $ this ->assertMatchesRegularExpression ('/\.{10} 10 \/ 10 \(100%\)/ ' , $ output );
299+
300+ // With a "~v[345]] or later~" regex configured.
301+ $ commandTester = $ this ->executeCommand ($ this ->pluginDir , ['--license-regex ' => '~v[345] or later~ ' ]);
302+ $ output = $ commandTester ->getDisplay ();
303+ $ this ->assertSame (0 , $ commandTester ->getStatusCode ());
304+ $ this ->assertMatchesRegularExpression ('/\.{10} 10 \/ 10 \(100%\)/ ' , $ output );
305+
306+ // With a "GNU GPL" regex configured.
307+ $ commandTester = $ this ->executeCommand ($ this ->pluginDir , ['--license-regex ' => '~GNU GPL~ ' ]);
308+ $ output = $ commandTester ->getDisplay ();
309+ $ this ->assertSame (0 , $ commandTester ->getStatusCode ());
310+ $ this ->assertMatchesRegularExpression ('/FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE/ ' , $ output );
311+ $ this ->assertMatchesRegularExpression ('/Value ".+invented-license IL v3 or later" does not match/ ' , $ output );
312+ }
313+
257314 public function testExecuteNoFiles ()
258315 {
259316 // Just random directory with no PHP files.
0 commit comments