Merge "AutoLoader: Use require_once rather than require"
[mediawiki.git] / tests / phpunit / includes / exception / MWExceptionTest.php
blob5c3564479dd76c89e2f7ed35b6137076c050dd2c
1 <?php
3 use MediaWiki\MainConfigNames;
5 /**
6 * @covers \MWException
7 * @author Antoine Musso
8 */
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() );
26 /**
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() {
40 return [
41 [ Exception::class ],
42 [ MWException::class ],
46 /**
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, [] );
53 global $wgOut;
54 $wgOut->disable();
56 $e = new class( 'Uh oh!' ) extends MWException {
57 public function report() {
58 global $wgOut;
59 $wgOut->addHTML( 'Oh no!' );
63 MWExceptionHandler::handleException( $e );
65 $this->assertStringContainsString( 'Oh no!', $wgOut->getHTML() );