diff options
author | Adam Cozzette <acozzette@google.com> | 2016-11-17 17:04:30 -0800 |
---|---|---|
committer | Adam Cozzette <acozzette@google.com> | 2016-11-17 17:04:30 -0800 |
commit | 5d63097fc2b7f405f53d6ca4ad3c1ebd98d80ddd (patch) | |
tree | 50d8116271f024e16334785464c794da85f3ce12 /php/tests/array_test.php | |
parent | 5a76e633ea9b5adb215e93fdc11e1c0c08b3fc74 (diff) | |
parent | cd315dcbadc02569e145bde16e3f66c2fbb08e31 (diff) | |
download | protobuf-5d63097fc2b7f405f53d6ca4ad3c1ebd98d80ddd.tar.gz protobuf-5d63097fc2b7f405f53d6ca4ad3c1ebd98d80ddd.tar.bz2 protobuf-5d63097fc2b7f405f53d6ca4ad3c1ebd98d80ddd.zip |
Merge branch 'master' into down-integrate-with-msvc-fix
Diffstat (limited to 'php/tests/array_test.php')
-rw-r--r-- | php/tests/array_test.php | 122 |
1 files changed, 87 insertions, 35 deletions
diff --git a/php/tests/array_test.php b/php/tests/array_test.php index 09d4dc82..a79a08bc 100644 --- a/php/tests/array_test.php +++ b/php/tests/array_test.php @@ -65,6 +65,17 @@ class RepeatedFieldTest extends PHPUnit_Framework_TestCase $this->assertSame(3, $arr[6]); $arr [7]= MAX_INT32_STRING; $this->assertSame(MAX_INT32, $arr[7]); + + // Test foreach. + $arr = new RepeatedField(GPBType::INT32); + for ($i = 0; $i < 3; $i++) { + $arr []= $i; + } + $i = 0; + foreach ($arr as $val) { + $this->assertSame($i++, $val); + } + $this->assertSame(3, $i); } /** @@ -225,46 +236,68 @@ class RepeatedFieldTest extends PHPUnit_Framework_TestCase // Test append. $arr []= MAX_INT64; - $this->assertSame(MAX_INT64, $arr[0]); $arr []= MIN_INT64; - $this->assertEquals(MIN_INT64, $arr[1]); - $arr []= 1.1; - $this->assertSame(1, $arr[2]); - $arr []= '2'; - $this->assertSame(2, $arr[3]); $arr []= '3.1'; - $this->assertSame(3, $arr[4]); $arr []= MAX_INT64_STRING; - $this->assertSame(MAX_INT64, $arr[5]); $arr []= MIN_INT64_STRING; - $this->assertEquals(MIN_INT64, $arr[6]); + if (PHP_INT_SIZE == 4) { + $this->assertSame(MAX_INT64, $arr[0]); + $this->assertSame(MIN_INT64, $arr[1]); + $this->assertSame('1', $arr[2]); + $this->assertSame('2', $arr[3]); + $this->assertSame('3', $arr[4]); + $this->assertSame(MAX_INT64_STRING, $arr[5]); + $this->assertSame(MIN_INT64_STRING, $arr[6]); + } else { + $this->assertSame(MAX_INT64, $arr[0]); + $this->assertSame(MIN_INT64, $arr[1]); + $this->assertSame(1, $arr[2]); + $this->assertSame(2, $arr[3]); + $this->assertSame(3, $arr[4]); + $this->assertSame(MAX_INT64, $arr[5]); + $this->assertSame(MIN_INT64, $arr[6]); + } + $this->assertEquals(7, count($arr)); for ($i = 0; $i < count($arr); $i++) { $arr[$i] = 0; - $this->assertSame(0, $arr[$i]); + if (PHP_INT_SIZE == 4) { + $this->assertSame('0', $arr[$i]); + } else { + $this->assertSame(0, $arr[$i]); + } } // Test set. $arr [0]= MAX_INT64; - $this->assertSame(MAX_INT64, $arr[0]); $arr [1]= MIN_INT64; - $this->assertEquals(MIN_INT64, $arr[1]); - $arr [2]= 1.1; - $this->assertSame(1, $arr[2]); - $arr [3]= '2'; - $this->assertSame(2, $arr[3]); $arr [4]= '3.1'; - $this->assertSame(3, $arr[4]); $arr [5]= MAX_INT64_STRING; - $this->assertSame(MAX_INT64, $arr[5]); $arr [6]= MIN_INT64_STRING; - $this->assertEquals(MIN_INT64, $arr[6]); + + if (PHP_INT_SIZE == 4) { + $this->assertSame(MAX_INT64_STRING, $arr[0]); + $this->assertSame(MIN_INT64_STRING, $arr[1]); + $this->assertSame('1', $arr[2]); + $this->assertSame('2', $arr[3]); + $this->assertSame('3', $arr[4]); + $this->assertSame(MAX_INT64_STRING, $arr[5]); + $this->assertEquals(MIN_INT64_STRING, $arr[6]); + } else { + $this->assertSame(MAX_INT64, $arr[0]); + $this->assertSame(MIN_INT64, $arr[1]); + $this->assertSame(1, $arr[2]); + $this->assertSame(2, $arr[3]); + $this->assertSame(3, $arr[4]); + $this->assertSame(MAX_INT64, $arr[5]); + $this->assertEquals(MIN_INT64, $arr[6]); + } } /** @@ -315,38 +348,57 @@ class RepeatedFieldTest extends PHPUnit_Framework_TestCase // Test append. $arr []= MAX_UINT64; - $this->assertEquals(MAX_UINT64, $arr[0]); - $arr []= 1.1; - $this->assertSame(1, $arr[1]); - $arr []= '2'; - $this->assertSame(2, $arr[2]); $arr []= '3.1'; - $this->assertSame(3, $arr[3]); $arr []= MAX_UINT64_STRING; - $this->assertEquals(MAX_UINT64, $arr[4]); - $this->assertEquals(5, count($arr)); + if (PHP_INT_SIZE == 4) { + $this->assertSame(MAX_UINT64_STRING, $arr[0]); + $this->assertSame('1', $arr[1]); + $this->assertSame('2', $arr[2]); + $this->assertSame('3', $arr[3]); + $this->assertSame(MAX_UINT64_STRING, $arr[4]); + } else { + $this->assertSame(MAX_UINT64, $arr[0]); + $this->assertSame(1, $arr[1]); + $this->assertSame(2, $arr[2]); + $this->assertSame(3, $arr[3]); + $this->assertSame(MAX_UINT64, $arr[4]); + $this->assertSame(5, count($arr)); + } + + $this->assertSame(5, count($arr)); for ($i = 0; $i < count($arr); $i++) { $arr[$i] = 0; - $this->assertSame(0, $arr[$i]); + if (PHP_INT_SIZE == 4) { + $this->assertSame('0', $arr[$i]); + } else { + $this->assertSame(0, $arr[$i]); + } } // Test set. $arr [0]= MAX_UINT64; - $this->assertEquals(MAX_UINT64, $arr[0]); - $arr [1]= 1.1; - $this->assertSame(1, $arr[1]); - $arr [2]= '2'; - $this->assertSame(2, $arr[2]); $arr [3]= '3.1'; - $this->assertSame(3, $arr[3]); $arr [4]= MAX_UINT64_STRING; - $this->assertEquals(MAX_UINT64, $arr[4]); + + if (PHP_INT_SIZE == 4) { + $this->assertSame(MAX_UINT64_STRING, $arr[0]); + $this->assertSame('1', $arr[1]); + $this->assertSame('2', $arr[2]); + $this->assertSame('3', $arr[3]); + $this->assertSame(MAX_UINT64_STRING, $arr[4]); + } else { + $this->assertSame(MAX_UINT64, $arr[0]); + $this->assertSame(1, $arr[1]); + $this->assertSame(2, $arr[2]); + $this->assertSame(3, $arr[3]); + $this->assertSame(MAX_UINT64, $arr[4]); + } } /** |