aboutsummaryrefslogtreecommitdiffhomepage
path: root/php/tests/map_field_test.php
diff options
context:
space:
mode:
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);
}
#########################################################