diff options
author | Paul Yang <TeBoring@users.noreply.github.com> | 2016-10-25 17:27:05 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-25 17:27:05 -0700 |
commit | 51c5ff889ccd3836c25f40baafb350f92c9ee103 (patch) | |
tree | 39ba93f36167e2ab73c25ac337da0a97a4df4970 /php/tests/array_test.php | |
parent | 58580da37357941d502805be3ae520441be77728 (diff) | |
download | protobuf-51c5ff889ccd3836c25f40baafb350f92c9ee103.tar.gz protobuf-51c5ff889ccd3836c25f40baafb350f92c9ee103.tar.bz2 protobuf-51c5ff889ccd3836c25f40baafb350f92c9ee103.zip |
Fix pure php implementation for 32-bit machine. (#2282)
Diffstat (limited to 'php/tests/array_test.php')
-rw-r--r-- | php/tests/array_test.php | 111 |
1 files changed, 76 insertions, 35 deletions
diff --git a/php/tests/array_test.php b/php/tests/array_test.php index 09d4dc82..a118b54c 100644 --- a/php/tests/array_test.php +++ b/php/tests/array_test.php @@ -225,46 +225,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 +337,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]); + } } /** |