2017-12-22 07:24:06 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
2021-04-12 02:04:17 +00:00
|
|
|
* Copyright (C) 2017 Kunal Mehta <legoktm@debian.org>
|
2017-12-22 07:24:06 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2019-10-06 04:54:59 +00:00
|
|
|
use PHPUnit\Framework\CodeCoverageException;
|
|
|
|
|
use PHPUnit\Util\Test;
|
|
|
|
|
|
2017-12-22 07:24:06 +00:00
|
|
|
/**
|
2020-03-08 18:32:53 +00:00
|
|
|
* Check that `@covers` tags are valid. PHPUnit only does this when generating
|
|
|
|
|
* code coverage reports, which is slow and we generally don't do that when
|
|
|
|
|
* running tests during development and pre-merge in CI.
|
2017-12-22 07:24:06 +00:00
|
|
|
*
|
|
|
|
|
* @since 1.31
|
|
|
|
|
*/
|
|
|
|
|
trait MediaWikiCoversValidator {
|
|
|
|
|
|
|
|
|
|
/**
|
2020-03-08 18:32:53 +00:00
|
|
|
* Assert that all "test*" methods in the host class have valid `@covers` tags.
|
2019-11-21 16:36:26 +00:00
|
|
|
*
|
2020-03-08 18:32:53 +00:00
|
|
|
* Don't use a data provider here because this assertion will be run many
|
|
|
|
|
* thousands of times in CI, and the implicit overhead from PHPUnit with
|
|
|
|
|
* generating and executing a test case around each becomes rather significant
|
|
|
|
|
* at that scale. Also, when using a data provider, the setUp() and tearDown()
|
|
|
|
|
* of the host class would be re-run for every check, which becomes very
|
|
|
|
|
* expensive for integration tests that involve databases.
|
2021-03-25 10:38:39 +00:00
|
|
|
* @coversNothing
|
2017-12-22 07:24:06 +00:00
|
|
|
*/
|
2020-03-08 18:32:53 +00:00
|
|
|
public function testValidCovers() {
|
|
|
|
|
$class = static::class;
|
2019-11-21 16:36:26 +00:00
|
|
|
foreach ( get_class_methods( $this ) as $method ) {
|
2022-04-13 13:44:41 +00:00
|
|
|
if ( str_starts_with( $method, 'test' ) ) {
|
2020-03-08 18:32:53 +00:00
|
|
|
try {
|
|
|
|
|
Test::getLinesToBeCovered( $class, $method );
|
|
|
|
|
} catch ( CodeCoverageException $ex ) {
|
|
|
|
|
$this->fail( "$class::$method: " . $ex->getMessage() );
|
|
|
|
|
}
|
2019-11-21 16:36:26 +00:00
|
|
|
}
|
2019-11-21 06:13:23 +00:00
|
|
|
}
|
2020-03-08 18:32:53 +00:00
|
|
|
|
|
|
|
|
$this->addToAssertionCount( 1 );
|
2017-12-22 07:24:06 +00:00
|
|
|
}
|
|
|
|
|
}
|