3 use MediaWiki\MainConfigNames
;
7 * @author Antoine Musso
9 class MWExceptionTest
extends MediaWikiIntegrationTestCase
{
11 public function testMwexceptionThrowing() {
12 $this->expectException( MWException
::class );
13 throw new MWException();
16 public function testUseMessageCache() {
17 $e = new MWException();
18 $this->assertTrue( $e->useMessageCache() );
21 public function testIsLoggable() {
22 $e = new MWException();
23 $this->assertTrue( $e->isLoggable() );
27 * Verify the exception classes are JSON serializabe.
29 * @dataProvider provideExceptionClasses
31 public function testJsonSerializeExceptions( $exception_class ) {
32 $json = MWExceptionHandler
::jsonSerializeException(
33 new $exception_class()
35 $this->assertIsString( $json,
36 "The $exception_class exception should be JSON serializable, got false." );
39 public static function provideExceptionClasses() {
42 [ MWException
::class ],
47 * @covers \MWException::report
49 public function testReport() {
50 // Turn off to keep mw-error.log file empty in CI (and thus avoid build failure)
51 $this->overrideConfigValue( MainConfigNames
::DebugLogGroups
, [] );
56 $e = new class( 'Uh oh!' ) extends MWException
{
57 public function report() {
59 $wgOut->addHTML( 'Oh no!' );
63 MWExceptionHandler
::handleException( $e );
65 $this->assertStringContainsString( 'Oh no!', $wgOut->getHTML() );