Rewrite MediaWikiCoversValidator to use @dataProvider

… and make use of yield. I believe the code is easier to read and
understand this way.

Depends-On: I898c09ec16521e6f8c60eb589843ccfc48d63025
Depends-On: Iaf212c8cf665ecae04e76600bc7a9f1d40a6c3c0
Change-Id: I4fc06bf76364cd15be81ab6c8532b9dac9ef012e
This commit is contained in:
Thiemo Kreuz 2019-11-21 17:36:26 +01:00 committed by Thiemo Kreuz (WMDE)
parent 9d67de01cb
commit 864d4fb4c8

View file

@ -33,25 +33,24 @@ trait MediaWikiCoversValidator {
/**
* Test that all methods in this class that begin
* with "test" have valid covers tags.
*
* @dataProvider providePHPUnitTestMethodNames
*/
public function testValidCovers() {
$methods = get_class_methods( $this );
$class = static::class;
$bad = '';
foreach ( $methods as $method ) {
if ( strpos( $method, 'test' ) === 0 ) {
try {
Test::getLinesToBeCovered( $class, $method );
} catch ( CodeCoverageException $e ) {
$bad .= "$class::$method: {$e->getMessage()}\n";
}
}
public function testValidCovers( $class, $method ) {
try {
Test::getLinesToBeCovered( $class, $method );
} catch ( CodeCoverageException $ex ) {
$this->fail( "$class::$method: " . $ex->getMessage() );
}
if ( $bad ) {
$this->fail( $bad );
} else {
$this->addToAssertionCount( 1 );
$this->addToAssertionCount( 1 );
}
public function providePHPUnitTestMethodNames() {
foreach ( get_class_methods( $this ) as $method ) {
if ( strncmp( $method, 'test', 4 ) === 0 ) {
yield [ static::class, $method ];
}
}
}
}