Adjust code coverage

-Exclude methods and classes that cannot be meaningfully covered
-Add a simple test for AbuseFilterServices
-Exclude ServiceWiring because there's no way to tell PHPUnit it's
covered

Change-Id: I4c67b0d3fea68c7a3b3cbe01b5608f87e1b492db
This commit is contained in:
Daimona Eaytoy 2020-11-19 18:49:55 +01:00
parent eab1f13696
commit 3f7fff56e8
6 changed files with 49 additions and 0 deletions

View file

@ -4,6 +4,9 @@ namespace MediaWiki\Extension\AbuseFilter\Filter;
use RuntimeException;
/**
* @codeCoverageIgnore
*/
class FilterNotFoundException extends RuntimeException {
/**
* @param int $filter

View file

@ -4,6 +4,9 @@ namespace MediaWiki\Extension\AbuseFilter\Filter;
use RuntimeException;
/**
* @codeCoverageIgnore
*/
class FilterVersionNotFoundException extends RuntimeException {
/**
* @param int $version

View file

@ -225,6 +225,7 @@ class FilterProfiler {
* @param int $totalFilters
* @param int $totalConditions
* @param float $runtime
* @codeCoverageIgnore
*/
public function recordRuntimeProfilingResult( int $totalFilters, int $totalConditions, float $runtime ) : void {
$keyPrefix = 'abusefilter.runtime-profile.' . $this->localWikiID . '.';

View file

@ -4,6 +4,9 @@ namespace MediaWiki\Extension\AbuseFilter;
use InvalidArgumentException;
/**
* @codeCoverageIgnore
*/
class InvalidImportDataException extends InvalidArgumentException {
/**
* @param string $data That is not valid

View file

@ -19,6 +19,10 @@ use MediaWiki\Extension\AbuseFilter\Parser\ParserFactory;
use MediaWiki\Logger\LoggerFactory;
use MediaWiki\MediaWikiServices;
// This file is actually covered by AbuseFilterServicesTest, but it's not possible to specify a path
// in @covers annotations (https://github.com/sebastianbergmann/phpunit/issues/3794)
// @codeCoverageIgnoreStart
return [
KeywordsManager::SERVICE_NAME => function ( MediaWikiServices $services ): KeywordsManager {
return new KeywordsManager(
@ -125,3 +129,5 @@ return [
);
},
];
// @codeCoverageIgnoreEnd

View file

@ -0,0 +1,33 @@
<?php
use MediaWiki\Extension\AbuseFilter\AbuseFilterServices;
/**
* @group Test
* @group AbuseFilter
*/
class AbuseFilterServicesTest extends MediaWikiIntegrationTestCase {
/**
* @covers \MediaWiki\Extension\AbuseFilter\AbuseFilterServices
* @param string $getter
* @dataProvider provideGetters
*/
public function testServiceGetters( string $getter ) {
// Methods are typehinted, so no need to assert
AbuseFilterServices::$getter();
$this->addToAssertionCount( 1 );
}
/**
* @return Generator
*/
public function provideGetters() : Generator {
$clazz = new ReflectionClass( AbuseFilterServices::class );
foreach ( $clazz->getMethods( ReflectionMethod::IS_PUBLIC ) as $method ) {
$name = $method->getName();
if ( strpos( $name, 'get' ) === 0 ) {
yield $name => [ $name ];
}
}
}
}