aboutsummaryrefslogtreecommitdiffhomepage
path: root/php/tests/map_field_test.php
diff options
context:
space:
mode:
authorGravatar Jisi Liu <jisi.liu@gmail.com>2017-07-25 11:52:33 -0700
committerGravatar Jisi Liu <jisi.liu@gmail.com>2017-07-25 11:52:33 -0700
commit759245a49a00315a41b28da8fe52a2894d4f57ea (patch)
tree5a0032a1a3619a448d5301da131907ca8449730f /php/tests/map_field_test.php
parent4bff88e0fb2338657a781eeee0c5362a57b57bf3 (diff)
Merge from master
Diffstat (limited to 'php/tests/map_field_test.php')
-rw-r--r--php/tests/map_field_test.php23
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);
}
#########################################################