From 3f7fff56e89008bd669c90e83d42e5858a7060a6 Mon Sep 17 00:00:00 2001 From: Daimona Eaytoy Date: Thu, 19 Nov 2020 18:49:55 +0100 Subject: [PATCH] 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 --- includes/Filter/FilterNotFoundException.php | 3 ++ .../Filter/FilterVersionNotFoundException.php | 3 ++ includes/FilterProfiler.php | 1 + includes/InvalidImportDataException.php | 3 ++ includes/ServiceWiring.php | 6 ++++ tests/phpunit/AbuseFilterServicesTest.php | 33 +++++++++++++++++++ 6 files changed, 49 insertions(+) create mode 100644 tests/phpunit/AbuseFilterServicesTest.php diff --git a/includes/Filter/FilterNotFoundException.php b/includes/Filter/FilterNotFoundException.php index 12e25bcf6..2ee76c270 100644 --- a/includes/Filter/FilterNotFoundException.php +++ b/includes/Filter/FilterNotFoundException.php @@ -4,6 +4,9 @@ namespace MediaWiki\Extension\AbuseFilter\Filter; use RuntimeException; +/** + * @codeCoverageIgnore + */ class FilterNotFoundException extends RuntimeException { /** * @param int $filter diff --git a/includes/Filter/FilterVersionNotFoundException.php b/includes/Filter/FilterVersionNotFoundException.php index e7d592acc..9e158e582 100644 --- a/includes/Filter/FilterVersionNotFoundException.php +++ b/includes/Filter/FilterVersionNotFoundException.php @@ -4,6 +4,9 @@ namespace MediaWiki\Extension\AbuseFilter\Filter; use RuntimeException; +/** + * @codeCoverageIgnore + */ class FilterVersionNotFoundException extends RuntimeException { /** * @param int $version diff --git a/includes/FilterProfiler.php b/includes/FilterProfiler.php index f35af1d26..d86400b7d 100644 --- a/includes/FilterProfiler.php +++ b/includes/FilterProfiler.php @@ -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 . '.'; diff --git a/includes/InvalidImportDataException.php b/includes/InvalidImportDataException.php index 3dd5b36be..951b99893 100644 --- a/includes/InvalidImportDataException.php +++ b/includes/InvalidImportDataException.php @@ -4,6 +4,9 @@ namespace MediaWiki\Extension\AbuseFilter; use InvalidArgumentException; +/** + * @codeCoverageIgnore + */ class InvalidImportDataException extends InvalidArgumentException { /** * @param string $data That is not valid diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php index 9d90c9998..98fa77d62 100644 --- a/includes/ServiceWiring.php +++ b/includes/ServiceWiring.php @@ -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 diff --git a/tests/phpunit/AbuseFilterServicesTest.php b/tests/phpunit/AbuseFilterServicesTest.php new file mode 100644 index 000000000..3c55deb66 --- /dev/null +++ b/tests/phpunit/AbuseFilterServicesTest.php @@ -0,0 +1,33 @@ +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 ]; + } + } + } +}