3 * Tests for includes/Exception.php.
5 * @author Antoine Musso
6 * @copyright Copyright © 2013, Antoine Musso
7 * @copyright Copyright © 2013, Wikimedia Foundation Inc.
11 class MWExceptionHandlerTest
extends MediaWikiTestCase
{
14 * @covers MWExceptionHandler::getRedactedTrace
16 function testGetRedactedTrace() {
18 $array = array( 'a', 'b' );
19 $object = new StdClass();
20 self
::helperThrowAnException( $array, $object );
21 } catch (Exception
$e) {
24 # Make sure our strack trace contains an array and an object passed to
25 # some function in the stacktrace. Else, we can not assert the trace
26 # redaction achieved its job.
27 $trace = $e->getTrace();
30 foreach ( $trace as $frame ) {
31 if ( ! isset( $frame['args'] ) ) {
34 foreach ( $frame['args'] as $arg ) {
35 $hasObject = $hasObject ||
is_object( $arg );
36 $hasArray = $hasArray ||
is_array( $arg );
39 if( $hasObject && $hasArray ) {
43 $this->assertTrue( $hasObject,
44 "The stacktrace must have a function having an object has parameter" );
45 $this->assertTrue( $hasArray,
46 "The stacktrace must have a function having an array has parameter" );
48 # Now we redact the trace.. and make sure no function arguments are
50 $redacted = MWExceptionHandler
::getRedactedTrace( $e );
52 foreach ( $redacted as $frame ) {
53 if ( ! isset( $frame['args'] ) ) {
56 foreach ( $frame['args'] as $arg ) {
57 $this->assertNotInternalType( 'array', $arg);
58 $this->assertNotInternalType( 'object', $arg);
64 * Helper function for testExpandArgumentsInCall
66 * Pass it an object and an array :-)
70 protected static function helperThrowAnException( $a, $b ) {
71 throw new Exception();