From: Brad Jorsch Date: Fri, 1 Nov 2013 18:33:21 +0000 (-0400) Subject: Add test for getRedactedTrace and reference args X-Git-Tag: 1.31.0-rc.0~18314 X-Git-Url: https://git.heureux-cyclage.org/w/index.php?a=commitdiff_plain;h=405acaeba6d980682ef26158e41dc4a834e51f3f;p=lhc%2Fweb%2Fwiklou.git Add test for getRedactedTrace and reference args 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 --- diff --git a/tests/phpunit/includes/MWExceptionHandlerTest.php b/tests/phpunit/includes/MWExceptionHandlerTest.php index 987dfa8347..aebd65f8ce 100644 --- a/tests/phpunit/includes/MWExceptionHandlerTest.php +++ b/tests/phpunit/includes/MWExceptionHandlerTest.php @@ -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(); } }