Skip to content

Commit

Permalink
Abstract tests do not need coverage data
Browse files Browse the repository at this point in the history
Coverage data for abstract classes is optional. In most cases it will
make sense to belong to the concrete class that implements it.
  • Loading branch information
andrewnicols committed Sep 18, 2023
1 parent 76ce969 commit 595b93d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion moodle/Sniffs/PHPUnit/TestCaseCoversSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Util\Tokens;
use PHPCSUtils\Utils\ObjectDeclarations;

/**
* Checks that a test file has the @coversxxx annotations properly defined.
Expand All @@ -46,7 +47,6 @@ public function register() {
* @param int $pointer The position in the stack.
*/
public function process(File $file, $pointer) {

// Before starting any check, let's look for various things.

// If we aren't checking Moodle 4.0dev (400) and up, nothing to check.
Expand Down Expand Up @@ -78,6 +78,12 @@ public function process(File $file, $pointer) {
// Iterate over all the classes (hopefully only one, but that's not this sniff problem).
$cStart = $pointer;
while ($cStart = $file->findNext(T_CLASS, $cStart + 1)) {
$classInfo = ObjectDeclarations::getClassProperties($file, $cStart);
if ($classInfo['is_abstract']) {
// Abstract classes are not tested.
// Coverage information belongs to the concrete classes that extend them.
continue;

Check warning on line 85 in moodle/Sniffs/PHPUnit/TestCaseCoversSniff.php

View check run for this annotation

Codecov / codecov/patch

moodle/Sniffs/PHPUnit/TestCaseCoversSniff.php#L85

Added line #L85 was not covered by tests
}
$class = $file->getDeclarationName($cStart);
$classCovers = false; // To control when the class has a @covers tag.
$classCoversNothing = false; // To control when the class has a @coversNothing tag.
Expand Down

0 comments on commit 595b93d

Please sign in to comment.