From 3a0382e9076bdbb7c764080c92f3c2324d852be7 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Thu, 13 Jul 2017 11:21:03 -0700 Subject: Add map iterator for c extension (#3350) --- php/tests/map_field_test.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'php/tests') 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); } ######################################################### -- cgit v1.2.3