Skip to content

Commit

Permalink
Move unit test method Missing Docblock to new code and skip test_ met…
Browse files Browse the repository at this point in the history
…hods (#127)

* Move unit test method Missing Docblock to new code, and 
* Ensure that test_* methods don't get a warning.

This allows it to be ignored in phpcs.xml.
  • Loading branch information
andrewnicols committed Mar 20, 2024
1 parent 6974134 commit 380108f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
11 changes: 10 additions & 1 deletion moodle/Sniffs/Commenting/MissingDocblockSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,16 @@ protected function processFunctions(File $phpcsFile, int $stackPtr): void {
$objectName = TokenUtil::getObjectName($phpcsFile, $typePtr);
$objectType = TokenUtil::getObjectType($phpcsFile, $typePtr);

if ($extendsOrImplements) {
if ($isUnitTestFile) {
if (substr($objectName, 0, 5) !== 'test_') {
$phpcsFile->addWarning(
'Missing docblock for %s %s in testcase',
$typePtr,
'MissingTestcaseMethodDescription',
[$objectType, $objectName]
);
}
} elseif ($extendsOrImplements) {
$phpcsFile->addWarning('Missing docblock for %s %s', $typePtr, 'Missing', [$objectType, $objectName]);
} else {
$phpcsFile->addError('Missing docblock for %s %s', $typePtr, 'Missing', [$objectType, $objectName]);
Expand Down
3 changes: 2 additions & 1 deletion moodle/Tests/Sniffs/Commenting/MissingDocblockSniffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ public static function docblockCorrectnessProvider(): array {
3 => 'Missing docblock for class example_test',
],
'warnings' => [
12 => 'Missing docblock for function test_the_thing',
15 => 'Missing docblock for function this_is_not_a_test in testcase',
18 => 'Missing docblock for function this_is_a_dataprovider in testcase',
],
],
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ public static function tearDownAfterClass(): void {
}
public function test_the_thing(): void {
}

public function this_is_not_a_test(): void {
}

public static function this_is_a_dataprovider(): array {
}
}

0 comments on commit 380108f

Please sign in to comment.