Improve ExtensionRegistry test coverage

Change-Id: I7f7445952f057995a3e3215145803affa5aceede
This commit is contained in:
Kunal Mehta 2018-02-10 00:03:19 -08:00
parent ad2a5758de
commit f492a981bf
2 changed files with 52 additions and 1 deletions

View file

@ -82,6 +82,7 @@ class ExtensionRegistry {
private static $instance;
/**
* @codeCoverageIgnore
* @return ExtensionRegistry
*/
public static function getInstance() {
@ -105,9 +106,11 @@ class ExtensionRegistry {
} else {
throw new Exception( "$path does not exist!" );
}
// @codeCoverageIgnoreStart
if ( !$mtime ) {
$err = error_get_last();
throw new Exception( "Couldn't stat $path: {$err['message']}" );
// @codeCoverageIgnoreEnd
}
}
$this->queued[$path] = $mtime;

View file

@ -1,9 +1,57 @@
<?php
/**
* @covers ExtensionRegistry
*/
class ExtensionRegistryTest extends MediaWikiTestCase {
private $dataDir;
public function setUp() {
parent::setUp();
$this->dataDir = __DIR__ . '/../../data/registration';
}
public function testQueue_invalid() {
$registry = new ExtensionRegistry();
$path = __DIR__ . '/doesnotexist.json';
$this->setExpectedException(
Exception::class,
"$path does not exist!"
);
$registry->queue( $path );
}
public function testQueue() {
$registry = new ExtensionRegistry();
$path = "{$this->dataDir}/good.json";
$registry->queue( $path );
$this->assertArrayHasKey(
$path,
$registry->getQueue()
);
$registry->clearQueue();
$this->assertEmpty( $registry->getQueue() );
}
public function testLoadFromQueue_empty() {
$registry = new ExtensionRegistry();
$registry->loadFromQueue();
$this->assertEmpty( $registry->getAllThings() );
}
public function testLoadFromQueue_late() {
$registry = new ExtensionRegistry();
$registry->finish();
$registry->queue( "{$this->dataDir}/good.json" );
$this->setExpectedException(
MWException::class,
"The following paths tried to load late: {$this->dataDir}/good.json"
);
$registry->loadFromQueue();
}
/**
* @covers ExtensionRegistry::exportExtractedData
* @dataProvider provideExportExtractedDataGlobals
*/
public function testExportExtractedDataGlobals( $desc, $before, $globals, $expected ) {