From 8deb49f534073304fd501a96ef3fac7bda4c76ce Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Thu, 14 Jan 2016 16:11:44 -0500 Subject: API: Work around PHP bug 45959 Sigh, PHP. You allow for an array to have string "1" as a key (e.g. when casting from object to array), but then you do everything wrong when trying to deal with it. Bug: T123663 Change-Id: I49f09901a69aab39ca1519bbe9e41267bf9a1216 --- tests/phpunit/includes/api/ApiResultTest.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tests/phpunit/includes/api/ApiResultTest.php') diff --git a/tests/phpunit/includes/api/ApiResultTest.php b/tests/phpunit/includes/api/ApiResultTest.php index 9dbde3d93fa1..292d276b681f 100644 --- a/tests/phpunit/includes/api/ApiResultTest.php +++ b/tests/phpunit/includes/api/ApiResultTest.php @@ -218,6 +218,17 @@ class ApiResultTest extends MediaWikiTestCase { 0 => "foo\xef\xbf\xbdbar", 1 => "\xc3\xa1", ), $arr ); + + $obj = new stdClass; + $obj->{'1'} = 'one'; + $arr = array(); + ApiResult::setValue( $arr, 'foo', $obj ); + $this->assertSame( array( + 'foo' => array( + 1 => 'one', + ApiResult::META_TYPE => 'assoc', + ) + ), $arr ); } /** @@ -509,6 +520,19 @@ class ApiResultTest extends MediaWikiTestCase { 1 => "\xc3\xa1", ApiResult::META_TYPE => 'assoc', ), $result->getResultData() ); + + $result = new ApiResult( 8388608 ); + $obj = new stdClass; + $obj->{'1'} = 'one'; + $arr = array(); + $result->addValue( $arr, 'foo', $obj ); + $this->assertSame( array( + 'foo' => array( + 1 => 'one', + ApiResult::META_TYPE => 'assoc', + ), + ApiResult::META_TYPE => 'assoc', + ), $result->getResultData() ); } /** -- cgit v1.2.3