MediaWiki
REL1_24
|
00001 <?php 00009 class MWExceptionHandlerTest extends MediaWikiTestCase { 00010 00014 public function testGetRedactedTrace() { 00015 $refvar = 'value'; 00016 try { 00017 $array = array( 'a', 'b' ); 00018 $object = new StdClass(); 00019 self::helperThrowAnException( $array, $object, $refvar ); 00020 } catch ( Exception $e ) { 00021 } 00022 00023 # Make sure our stack trace contains an array and an object passed to 00024 # some function in the stacktrace. Else, we can not assert the trace 00025 # redaction achieved its job. 00026 $trace = $e->getTrace(); 00027 $hasObject = false; 00028 $hasArray = false; 00029 foreach ( $trace as $frame ) { 00030 if ( !isset( $frame['args'] ) ) { 00031 continue; 00032 } 00033 foreach ( $frame['args'] as $arg ) { 00034 $hasObject = $hasObject || is_object( $arg ); 00035 $hasArray = $hasArray || is_array( $arg ); 00036 } 00037 00038 if ( $hasObject && $hasArray ) { 00039 break; 00040 } 00041 } 00042 $this->assertTrue( $hasObject, 00043 "The stacktrace must have a function having an object has parameter" ); 00044 $this->assertTrue( $hasArray, 00045 "The stacktrace must have a function having an array has parameter" ); 00046 00047 # Now we redact the trace.. and make sure no function arguments are 00048 # arrays or objects. 00049 $redacted = MWExceptionHandler::getRedactedTrace( $e ); 00050 00051 foreach ( $redacted as $frame ) { 00052 if ( !isset( $frame['args'] ) ) { 00053 continue; 00054 } 00055 foreach ( $frame['args'] as $arg ) { 00056 $this->assertNotInternalType( 'array', $arg ); 00057 $this->assertNotInternalType( 'object', $arg ); 00058 } 00059 } 00060 00061 $this->assertEquals( 'value', $refvar, 'Ensuring reference variable wasn\'t changed' ); 00062 } 00063 00071 protected static function helperThrowAnException( $a, $b, &$c ) { 00072 throw new Exception(); 00073 } 00074 }