wiki.techinc.nl/tests/phpunit/includes/api/PrefixUniquenessTest.php
Thiemo Mättig 23632a4ecd Use precise ApiMain/ApiQuery type hints in all API modules
Which type is used depends on the ApiModuleManager responsible for
the API module. There are two managers, one in ApiMain and one in
ApiQuery. Both contain a list of API modules they instantiate.
Both use $this as the first parameter in the constructors of the
individual modules. There is no other regular way to instantiate the
modules, so we know the type must either be ApiMain or ApiQuery.

The lists don't intersect.

I would have prefered the naming scheme $mainModule for ApiMain
modules and $queryModule for ApiQuery modules but since this
doesn't add much I left the shorter variable names untouched.

Change-Id: Ie6bf19150f1c9b619655a06a8e051412665e54db
2014-05-16 11:07:23 -04:00

27 lines
827 B
PHP

<?php
/**
* Checks that all API query modules, core and extensions, have unique prefixes.
*
* @group API
*/
class PrefixUniquenessTest extends MediaWikiTestCase {
public function testPrefixes() {
$main = new ApiMain( new FauxRequest() );
$query = new ApiQuery( $main, 'foo', 'bar' );
$modules = $query->getModuleManager()->getNamesWithClasses();
$prefixes = array();
foreach ( $modules as $name => $class ) {
/** @var ApiQueryBase $module */
$module = new $class( $query, $name );
$prefix = $module->getModulePrefix();
if ( isset( $prefixes[$prefix] ) ) {
$this->fail( "Module prefix '{$prefix}' is shared between {$class} and {$prefixes[$prefix]}" );
}
$prefixes[$module->getModulePrefix()] = $class;
}
$this->assertTrue( true ); // dummy call to make this test non-incomplete
}
}