From: jenkins-bot Date: Tue, 13 Feb 2018 04:45:01 +0000 (+0000) Subject: Merge "Improve ExtensionRegistry test coverage" X-Git-Tag: 1.31.0-rc.0~621 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=0a066a7eee1f86e1f5efb494f6f60bbfa255c832;hp=331c9f9e2e59ee7a13e0da471f067f12b1915ea3 Merge "Improve ExtensionRegistry test coverage" --- diff --git a/includes/registration/ExtensionRegistry.php b/includes/registration/ExtensionRegistry.php index d14a5eeeb1..1876645399 100644 --- a/includes/registration/ExtensionRegistry.php +++ b/includes/registration/ExtensionRegistry.php @@ -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; diff --git a/tests/phpunit/includes/registration/ExtensionRegistryTest.php b/tests/phpunit/includes/registration/ExtensionRegistryTest.php index a6f69b64d9..67bc088d78 100644 --- a/tests/phpunit/includes/registration/ExtensionRegistryTest.php +++ b/tests/phpunit/includes/registration/ExtensionRegistryTest.php @@ -1,9 +1,57 @@ 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 ) {