aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php
diff options
context:
space:
mode:
authorTimo Tijhof <krinklemail@gmail.com>2020-02-21 00:26:07 +0000
committerTimo Tijhof <krinklemail@gmail.com>2020-02-21 23:54:33 +0000
commita3ce1f9da7500382ed6e68e0387b92d8101f5643 (patch)
tree1c7c0eddc81e25242bc114dc60a5a5ec38fec981 /tests/phpunit/includes/resourceloader/ResourceLoaderTest.php
parent5b2311d0c59f4b2d60822c493960654bf288b22d (diff)
downloadmediawikicore-a3ce1f9da7500382ed6e68e0387b92d8101f5643.tar.gz
mediawikicore-a3ce1f9da7500382ed6e68e0387b92d8101f5643.zip
resourceloader: Add more granular phan type information in various classes
* Where possible and easy to figure out, change `array` to something like `array<K,V>` or `V[]` for improved static analysis to catch/prevent regressions in CI. * Minor doc improvements: - consistently use the imperative mood for method briefs, - consistently use @internal instead of @private, - explain in @throws why they happen to inform when they should be caught (and remove if they are not meant to be caught/handled by any caller). * Simplify addSources() implementation as a simple loop instead recursing (not worth the complexity, only called once or twice at runtime). * Use more granular exceptions to distinguish between errors that indicate a mistake on the caller (logic/invalid arguments error), and runtime errors (which are more circumstantial). * Update register() unit test for bad 'moduleInfo' type to use a nested value, given that the second-parameter level type is now verified by the signature already. Change-Id: Id98ba1f28cb7f1c72f0a3e82f4151bcbd0f3db77
Diffstat (limited to 'tests/phpunit/includes/resourceloader/ResourceLoaderTest.php')
-rw-r--r--tests/phpunit/includes/resourceloader/ResourceLoaderTest.php24
1 files changed, 10 insertions, 14 deletions
diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php
index 66ee61332b57..2695907f88d6 100644
--- a/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php
+++ b/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php
@@ -102,7 +102,7 @@ class ResourceLoaderTest extends ResourceLoaderTestCase {
*/
public function testRegisterInvalidName() {
$resourceLoader = new EmptyResourceLoader();
- $this->expectException( MWException::class );
+ $this->expectException( InvalidArgumentException::class );
$this->expectExceptionMessage( "name 'test!invalid' is invalid" );
$resourceLoader->register( 'test!invalid', [] );
}
@@ -114,7 +114,7 @@ class ResourceLoaderTest extends ResourceLoaderTestCase {
$resourceLoader = new EmptyResourceLoader();
$this->expectException( InvalidArgumentException::class );
$this->expectExceptionMessage( 'Invalid module info' );
- $resourceLoader->register( 'test', new stdClass() );
+ $resourceLoader->register( [ 'test' => new stdClass() ] );
}
/**
@@ -372,8 +372,8 @@ class ResourceLoaderTest extends ResourceLoaderTestCase {
*/
public function testAddSourceDupe() {
$rl = new EmptyResourceLoader;
- $this->expectException( MWException::class );
- $this->expectExceptionMessage( 'ResourceLoader duplicate source addition error' );
+ $this->expectException( RuntimeException::class );
+ $this->expectExceptionMessage( 'Cannot register source' );
$rl->addSource( 'foo', 'https://example.org/w/load.php' );
$rl->addSource( 'foo', 'https://example.com/w/load.php' );
}
@@ -383,8 +383,8 @@ class ResourceLoaderTest extends ResourceLoaderTestCase {
*/
public function testAddSourceInvalid() {
$rl = new EmptyResourceLoader;
- $this->expectException( MWException::class );
- $this->expectExceptionMessage( 'with no "loadScript" key' );
+ $this->expectException( InvalidArgumentException::class );
+ $this->expectExceptionMessage( 'must have a "loadScript" key' );
$rl->addSource( 'foo', [ 'x' => 'https://example.org/w/load.php' ] );
}
@@ -544,8 +544,8 @@ END
* @covers ResourceLoader::makeLoaderImplementScript
*/
public function testMakeLoaderImplementScriptInvalid() {
- $this->expectException( MWException::class );
- $this->expectExceptionMessage( 'Invalid scripts error' );
+ $this->expectException( InvalidArgumentException::class );
+ $this->expectExceptionMessage( 'Script must be a' );
$rl = TestingAccessWrapper::newFromClass( ResourceLoader::class );
$context = new ResourceLoaderContext( new EmptyResourceLoader(), new FauxRequest() );
$rl->makeLoaderImplementScript(
@@ -672,12 +672,8 @@ END
$this->assertEquals( $rl->getLoadScript( $name ), $sources[$name]['loadScript'] );
}
- try {
- $rl->getLoadScript( 'thiswasneverreigstered' );
- $this->assertTrue( false, 'ResourceLoader::getLoadScript should have thrown an exception' );
- } catch ( MWException $e ) {
- $this->assertTrue( true );
- }
+ $this->expectException( UnexpectedValueException::class );
+ $rl->getLoadScript( 'thiswasneverregistered' );
}
protected function getFailFerryMock( $getter = 'getScript' ) {