*/
public function testRegisterInvalidName() {
$resourceLoader = new EmptyResourceLoader();
- $this->setExpectedException( 'MWException', "name 'test!invalid' is invalid" );
+ $this->setExpectedException( MWException::class, "name 'test!invalid' is invalid" );
$resourceLoader->register( 'test!invalid', new ResourceLoaderTestModule() );
}
*/
public function testRegisterInvalidType() {
$resourceLoader = new EmptyResourceLoader();
- $this->setExpectedException( 'MWException', 'ResourceLoader module info type error' );
+ $this->setExpectedException( MWException::class, 'ResourceLoader module info type error' );
$resourceLoader->register( 'test', new stdClass() );
}
*/
public function testAddSourceDupe() {
$rl = new ResourceLoader;
- $this->setExpectedException( 'MWException', 'ResourceLoader duplicate source addition error' );
+ $this->setExpectedException(
+ MWException::class, 'ResourceLoader duplicate source addition error'
+ );
$rl->addSource( 'foo', 'https://example.org/w/load.php' );
$rl->addSource( 'foo', 'https://example.com/w/load.php' );
}
*/
public function testAddSourceInvalid() {
$rl = new ResourceLoader;
- $this->setExpectedException( 'MWException', 'with no "loadScript" key' );
+ $this->setExpectedException( MWException::class, 'with no "loadScript" key' );
$rl->addSource( 'foo', [ 'x' => 'https://example.org/w/load.php' ] );
}
ResourceLoader::clearCache();
$this->setMwGlobals( 'wgResourceLoaderDebug', true );
- $rl = TestingAccessWrapper::newFromClass( 'ResourceLoader' );
+ $rl = TestingAccessWrapper::newFromClass( ResourceLoader::class );
$this->assertEquals(
$case['expected'],
$rl->makeLoaderImplementScript(
* @covers ResourceLoader::makeLoaderImplementScript
*/
public function testMakeLoaderImplementScriptInvalid() {
- $this->setExpectedException( 'MWException', 'Invalid scripts error' );
- $rl = TestingAccessWrapper::newFromClass( 'ResourceLoader' );
+ $this->setExpectedException( MWException::class, 'Invalid scripts error' );
+ $rl = TestingAccessWrapper::newFromClass( ResourceLoader::class );
$rl->makeLoaderImplementScript(
'test', // name
123, // scripts
'foo' => self::getSimpleModuleMock( 'foo();' ),
'ferry' => self::getFailFerryMock(),
'bar' => self::getSimpleModuleMock( 'bar();' ),
- 'startup' => [ 'class' => 'ResourceLoaderStartUpModule' ],
+ 'startup' => [ 'class' => ResourceLoaderStartUpModule::class ],
] );
$context = $this->getResourceLoaderContext(
[
'Extra headers'
);
}
+
+ /**
+ * @covers ResourceLoader::respond
+ */
+ public function testRespond() {
+ $rl = $this->getMockBuilder( EmptyResourceLoader::class )
+ ->setMethods( [
+ 'tryRespondNotModified',
+ 'sendResponseHeaders',
+ 'measureResponseTime',
+ ] )
+ ->getMock();
+ $context = $this->getResourceLoaderContext( [ 'modules' => '' ], $rl );
+
+ $rl->expects( $this->once() )->method( 'measureResponseTime' );
+ $this->expectOutputRegex( '/no modules were requested/' );
+
+ $rl->respond( $context );
+ }
+
+ /**
+ * @covers ResourceLoader::measureResponseTime
+ */
+ public function testMeasureResponseTime() {
+ $stats = $this->getMockBuilder( NullStatsdDataFactory::class )
+ ->setMethods( [ 'timing' ] )->getMock();
+ $this->setService( 'StatsdDataFactory', $stats );
+
+ $stats->expects( $this->once() )->method( 'timing' )
+ ->with( 'resourceloader.responseTime', $this->anything() );
+
+ $timing = new Timing();
+ $timing->mark( 'requestShutdown' );
+ $rl = TestingAccessWrapper::newFromObject( new EmptyResourceLoader );
+ $rl->measureResponseTime( $timing );
+ DeferredUpdates::doUpdates();
+ }
}