From 405acaeba6d980682ef26158e41dc4a834e51f3f Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Fri, 1 Nov 2013 14:33:21 -0400 Subject: [PATCH] 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 --- tests/phpunit/includes/MWExceptionHandlerTest.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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(); } } -- 2.20.1