diff options
author | Paul Yang <TeBoring@users.noreply.github.com> | 2017-07-25 00:49:16 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-25 00:49:16 -0700 |
commit | 451d061141a14021ff95a093967827cd548720ba (patch) | |
tree | 84c032c0e1ffd34b6a8b97cc342ede6c0f257f9f /php/tests/map_field_test.php | |
parent | a713b73076f1d90bdc39ea8805b50421a59d7986 (diff) |
Fix cycle dependency for repeated field not collected by gc (#3399)
Diffstat (limited to 'php/tests/map_field_test.php')
-rw-r--r-- | php/tests/map_field_test.php | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/php/tests/map_field_test.php b/php/tests/map_field_test.php index 120b1bde..cffa2526 100644 --- a/php/tests/map_field_test.php +++ b/php/tests/map_field_test.php @@ -417,6 +417,29 @@ class MapFieldTest extends PHPUnit_Framework_TestCase { $this->assertSame(1, $arr[0]->getA()); $this->assertEquals(1, count($arr)); + + // Test foreach. + $arr = new MapField(GPBType::INT32, + GPBType::MESSAGE, TestMessage_Sub::class); + for ($i = 0; $i < 3; $i++) { + $arr[$i] = new TestMessage_Sub();; + $arr[$i]->setA($i); + } + $i = 0; + $key_test = []; + $value_test = []; + foreach ($arr as $key => $val) { + $key_test[] = $key; + $value_test[] = $val->getA(); + $i++; + } + $this->assertTrue(isset($key_test['0'])); + $this->assertTrue(isset($key_test['1'])); + $this->assertTrue(isset($key_test['2'])); + $this->assertTrue(isset($value_test['0'])); + $this->assertTrue(isset($value_test['1'])); + $this->assertTrue(isset($value_test['2'])); + $this->assertSame(3, $i); } ######################################################### |