Add test for getRedactedTrace and reference args
authorBrad Jorsch <bjorsch@wikimedia.org>
Fri, 1 Nov 2013 18:33:21 +0000 (14:33 -0400)
committerHashar <hashar@free.fr>
Fri, 1 Nov 2013 23:36:13 +0000 (23:36 +0000)
This tests the issue PleaseStand noticed when reviewing I3d570a63, where
if some function in the call stack took arguments by reference then
passing the exception to MWExceptionHandler::getRedactedTrace would
clobber those arguments.

Change-Id: Iaaba3ef2fb5eb6a338ab229201105ed4308b0692

tests/phpunit/includes/MWExceptionHandlerTest.php

index 987dfa8..aebd65f 100644 (file)
@@ -14,10 +14,11 @@ class MWExceptionHandlerTest extends MediaWikiTestCase {
         * @covers MWExceptionHandler::getRedactedTrace
         */
        function testGetRedactedTrace() {
+               $refvar = 'value';
                try {
                        $array = array( 'a', 'b' );
                        $object = new StdClass();
-                       self::helperThrowAnException( $array, $object );
+                       self::helperThrowAnException( $array, $object, $refvar );
                } catch (Exception $e) {
                }
 
@@ -58,16 +59,18 @@ class MWExceptionHandlerTest extends MediaWikiTestCase {
                                $this->assertNotInternalType( 'object', $arg);
                        }
                }
+
+               $this->assertEquals( 'value', $refvar, 'Ensuring reference variable wasn\'t changed' );
        }
 
        /**
         * Helper function for testExpandArgumentsInCall
         *
-        * Pass it an object and an array :-)
+        * Pass it an object and an array, and something by reference :-)
         *
         * @throws Exception
         */
-       protected static function helperThrowAnException( $a, $b ) {
+       protected static function helperThrowAnException( $a, $b, &$c ) {
                throw new Exception();
        }
 }