aboutsummaryrefslogtreecommitdiffhomepage
path: root/php/tests
diff options
context:
space:
mode:
authorGravatar Paul Yang <TeBoring@users.noreply.github.com>2017-07-13 11:21:03 -0700
committerGravatar GitHub <noreply@github.com>2017-07-13 11:21:03 -0700
commit3a0382e9076bdbb7c764080c92f3c2324d852be7 (patch)
tree61c1b903d5db55e23c2c60ec1b0829d1fcf06453 /php/tests
parentd3bbf1c8a98fe01c115f525c516e575d87c11a47 (diff)
Add map iterator for c extension (#3350)
Diffstat (limited to 'php/tests')
-rw-r--r--php/tests/map_field_test.php34
1 files changed, 34 insertions, 0 deletions
diff --git a/php/tests/map_field_test.php b/php/tests/map_field_test.php
index c5d21264..120b1bde 100644
--- a/php/tests/map_field_test.php
+++ b/php/tests/map_field_test.php
@@ -56,6 +56,23 @@ class MapFieldTest extends PHPUnit_Framework_TestCase {
unset($arr['3.1']);
unset($arr[MAX_INT32_STRING]);
$this->assertEquals(0, count($arr));
+
+ // Test foreach.
+ $arr = new MapField(GPBType::INT32, GPBType::INT32);
+ for ($i = 0; $i < 3; $i++) {
+ $arr[$i] = $i;
+ }
+ $i = 0;
+ $arr_test = [];
+ foreach ($arr as $key => $val) {
+ $this->assertSame($key, $val);
+ $arr_test[] = $key;
+ $i++;
+ }
+ $this->assertTrue(isset($arr_test[0]));
+ $this->assertTrue(isset($arr_test[1]));
+ $this->assertTrue(isset($arr_test[2]));
+ $this->assertSame(3, $i);
}
#########################################################
@@ -366,6 +383,23 @@ class MapFieldTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(1, count($arr));
unset($arr[True]);
$this->assertEquals(0, count($arr));
+
+ // Test foreach.
+ $arr = new MapField(GPBType::STRING, GPBType::STRING);
+ for ($i = 0; $i < 3; $i++) {
+ $arr[$i] = $i;
+ }
+ $i = 0;
+ $arr_test = [];
+ foreach ($arr as $key => $val) {
+ $this->assertSame($key, $val);
+ $arr_test[] = $key;
+ $i++;
+ }
+ $this->assertTrue(isset($arr_test['0']));
+ $this->assertTrue(isset($arr_test['1']));
+ $this->assertTrue(isset($arr_test['2']));
+ $this->assertSame(3, $i);
}
#########################################################