diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/phpunit/includes/exception/MWExceptionTest.php | 20 | ||||
-rw-r--r-- | tests/phpunit/unit/includes/exception/MWExceptionHandlerTest.php | 30 |
2 files changed, 12 insertions, 38 deletions
diff --git a/tests/phpunit/includes/exception/MWExceptionTest.php b/tests/phpunit/includes/exception/MWExceptionTest.php index 5c3564479dd7..8e4bd94e8a5e 100644 --- a/tests/phpunit/includes/exception/MWExceptionTest.php +++ b/tests/phpunit/includes/exception/MWExceptionTest.php @@ -24,26 +24,6 @@ class MWExceptionTest extends MediaWikiIntegrationTestCase { } /** - * Verify the exception classes are JSON serializabe. - * - * @dataProvider provideExceptionClasses - */ - public function testJsonSerializeExceptions( $exception_class ) { - $json = MWExceptionHandler::jsonSerializeException( - new $exception_class() - ); - $this->assertIsString( $json, - "The $exception_class exception should be JSON serializable, got false." ); - } - - public static function provideExceptionClasses() { - return [ - [ Exception::class ], - [ MWException::class ], - ]; - } - - /** * @covers \MWException::report */ public function testReport() { diff --git a/tests/phpunit/unit/includes/exception/MWExceptionHandlerTest.php b/tests/phpunit/unit/includes/exception/MWExceptionHandlerTest.php index 8fb9dfc07b60..d5f57451fa61 100644 --- a/tests/phpunit/unit/includes/exception/MWExceptionHandlerTest.php +++ b/tests/phpunit/unit/includes/exception/MWExceptionHandlerTest.php @@ -133,23 +133,21 @@ TEXT; } /** - * @dataProvider provideJsonSerializedKeys + * @dataProvider provideGetStructuredExceptionDataKeys * @param string $expectedKeyType Type expected as returned by get_debug_type() * @param string $exClass An exception class (ie: Exception, MWException) * @param string $key Name of the key to validate in the serialized JSON */ - public function testJsonserializeexceptionKeys( $expectedKeyType, $exClass, $key ) { - $json = json_decode( - MWExceptionHandler::jsonSerializeException( new $exClass() ) - ); - $this->assertObjectHasProperty( $key, $json ); - $this->assertSame( $expectedKeyType, get_debug_type( $json->$key ), "Type of the '$key' key" ); + public function testGetStructuredExceptionDataKeys( $expectedKeyType, $exClass, $key ) { + $data = MWExceptionHandler::getStructuredExceptionData( new $exClass() ); + $this->assertArrayHasKey( $key, $data ); + $this->assertSame( $expectedKeyType, get_debug_type( $data[$key] ), "Type of the '$key' key" ); } /** * Each case provides: [ type, exception class, key name ] */ - public static function provideJsonSerializedKeys() { + public static function provideGetStructuredExceptionDataKeys() { foreach ( [ Exception::class, MWException::class ] as $exClass ) { yield [ 'string', $exClass, 'id' ]; yield [ 'string', $exClass, 'file' ]; @@ -165,26 +163,22 @@ TEXT; * Given wgLogExceptionBacktrace is true * then serialized exception must have a backtrace */ - public function testJsonserializeexceptionBacktracingEnabled() { + public function testGetStructuredExceptionDataBacktracingEnabled() { TestingAccessWrapper::newFromClass( MWExceptionHandler::class ) ->logExceptionBacktrace = true; - $json = json_decode( - MWExceptionHandler::jsonSerializeException( new Exception() ) - ); - $this->assertObjectHasProperty( 'backtrace', $json ); + $data = MWExceptionHandler::getStructuredExceptionData( new Exception() ); + $this->assertArrayHasKey( 'backtrace', $data ); } /** * Given wgLogExceptionBacktrace is false * then serialized exception must not have a backtrace */ - public function testJsonserializeexceptionBacktracingDisabled() { + public function testGetStructuredExceptionDataBacktracingDisabled() { TestingAccessWrapper::newFromClass( MWExceptionHandler::class ) ->logExceptionBacktrace = false; - $json = json_decode( - MWExceptionHandler::jsonSerializeException( new Exception() ) - ); - $this->assertObjectNotHasProperty( 'backtrace', $json ); + $data = MWExceptionHandler::getStructuredExceptionData( new Exception() ); + $this->assertArrayNotHasKey( 'backtrace', $data ); } /** |