diff options
author | Brad Jorsch <bjorsch@wikimedia.org> | 2016-01-14 16:11:44 -0500 |
---|---|---|
committer | Brad Jorsch <bjorsch@wikimedia.org> | 2016-01-14 16:13:04 -0500 |
commit | 8deb49f534073304fd501a96ef3fac7bda4c76ce (patch) | |
tree | eaa7d80d2b3d41483c71735a68538253789d540e /tests/phpunit/includes | |
parent | 10917c08720a648b060990c76691c0e4bcc18712 (diff) | |
download | mediawikicore-8deb49f534073304fd501a96ef3fac7bda4c76ce.tar.gz mediawikicore-8deb49f534073304fd501a96ef3fac7bda4c76ce.zip |
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
Diffstat (limited to 'tests/phpunit/includes')
-rw-r--r-- | tests/phpunit/includes/api/ApiResultTest.php | 24 |
1 files changed, 24 insertions, 0 deletions
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() ); } /** |