| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\MainConfigNames; |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
class MWExceptionTest extends MediaWikiIntegrationTestCase { |
| 10 |
|
| 11 |
public function testMwexceptionThrowing() { |
| 12 |
$this->expectException( MWException::class ); |
| 13 |
throw new MWException(); |
| 14 |
} |
| 15 |
|
| 16 |
public function testUseMessageCache() { |
| 17 |
$e = new MWException(); |
| 18 |
$this->assertTrue( $e->useMessageCache() ); |
| 19 |
} |
| 20 |
|
| 21 |
public function testIsLoggable() { |
| 22 |
$e = new MWException(); |
| 23 |
$this->assertTrue( $e->isLoggable() ); |
| 24 |
} |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
public function testJsonSerializeExceptions( $exception_class ) { |
| 32 |
$json = MWExceptionHandler::jsonSerializeException( |
| 33 |
new $exception_class() |
| 34 |
); |
| 35 |
$this->assertIsString( $json, |
| 36 |
"The $exception_class exception should be JSON serializable, got false." ); |
| 37 |
} |
| 38 |
|
| 39 |
public static function provideExceptionClasses() { |
| 40 |
return [ |
| 41 |
[ Exception::class ], |
| 42 |
[ MWException::class ], |
| 43 |
]; |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
public function testReport() { |
| 50 |
|
| 51 |
$this->overrideConfigValue( MainConfigNames::DebugLogGroups, [] ); |
| 52 |
|
| 53 |
global $wgOut; |
| 54 |
$wgOut->disable(); |
| 55 |
|
| 56 |
$e = new class( 'Uh oh!' ) extends MWException { |
| 57 |
public function report() { |
| 58 |
global $wgOut; |
| 59 |
$wgOut->addHTML( 'Oh no!' ); |
| 60 |
} |
| 61 |
}; |
| 62 |
|
| 63 |
MWExceptionHandler::handleException( $e ); |
| 64 |
|
| 65 |
$this->assertStringContainsString( 'Oh no!', $wgOut->getHTML() ); |
| 66 |
} |
| 67 |
|
| 68 |
} |