diff options
author | Yilun Chong <chongyilun250@sina.com> | 2017-06-30 17:38:50 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-30 17:38:50 -0700 |
commit | e82ba0b8026eb16c40ceba861f02c643c36e8232 (patch) | |
tree | 2aa89a917c6091923682221026507aa9eea1aba4 /php/tests/array_test.php | |
parent | 726ba33d98cd06c268f88b7dedf2a9a7916d978d (diff) | |
parent | ecca6ea95d56a6f70ff7b223ec3f904758acc8b1 (diff) | |
download | protobuf-e82ba0b8026eb16c40ceba861f02c643c36e8232.tar.gz protobuf-e82ba0b8026eb16c40ceba861f02c643c36e8232.tar.bz2 protobuf-e82ba0b8026eb16c40ceba861f02c643c36e8232.zip |
Merge branch 'master' into ConformanceTestYilunChong
Diffstat (limited to 'php/tests/array_test.php')
-rw-r--r-- | php/tests/array_test.php | 625 |
1 files changed, 108 insertions, 517 deletions
diff --git a/php/tests/array_test.php b/php/tests/array_test.php index b55408da..271389ba 100644 --- a/php/tests/array_test.php +++ b/php/tests/array_test.php @@ -19,23 +19,23 @@ class RepeatedFieldTest extends PHPUnit_Framework_TestCase $arr = new RepeatedField(GPBType::INT32); // Test append. - $arr []= MAX_INT32; + $arr[] = MAX_INT32; $this->assertSame(MAX_INT32, $arr[0]); - $arr []= MIN_INT32; + $arr[] = MIN_INT32; $this->assertSame(MIN_INT32, $arr[1]); - $arr []= 1.1; + $arr[] = 1.1; $this->assertSame(1, $arr[2]); - $arr []= MAX_INT32_FLOAT; + $arr[] = MAX_INT32_FLOAT; $this->assertSame(MAX_INT32, $arr[3]); - $arr []= MAX_INT32_FLOAT; + $arr[] = MAX_INT32_FLOAT; $this->assertSame(MAX_INT32, $arr[4]); - $arr []= '2'; + $arr[] = '2'; $this->assertSame(2, $arr[5]); - $arr []= '3.1'; + $arr[] = '3.1'; $this->assertSame(3, $arr[6]); - $arr []= MAX_INT32_STRING; + $arr[] = MAX_INT32_STRING; $this->assertSame(MAX_INT32, $arr[7]); $this->assertEquals(8, count($arr)); @@ -46,29 +46,29 @@ class RepeatedFieldTest extends PHPUnit_Framework_TestCase } // Test set. - $arr [0]= MAX_INT32; + $arr[0] = MAX_INT32; $this->assertSame(MAX_INT32, $arr[0]); - $arr [1]= MIN_INT32; + $arr[1] = MIN_INT32; $this->assertSame(MIN_INT32, $arr[1]); - $arr [2]= 1.1; + $arr[2] = 1.1; $this->assertSame(1, $arr[2]); - $arr [3]= MAX_INT32_FLOAT; + $arr[3] = MAX_INT32_FLOAT; $this->assertSame(MAX_INT32, $arr[3]); - $arr [4]= MAX_INT32_FLOAT; + $arr[4] = MAX_INT32_FLOAT; $this->assertSame(MAX_INT32, $arr[4]); - $arr [5]= '2'; + $arr[5] = '2'; $this->assertSame(2, $arr[5]); - $arr [6]= '3.1'; + $arr[6] = '3.1'; $this->assertSame(3, $arr[6]); - $arr [7]= MAX_INT32_STRING; + $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; + $arr[] = $i; } $i = 0; foreach ($arr as $val) { @@ -77,44 +77,6 @@ class RepeatedFieldTest extends PHPUnit_Framework_TestCase $this->assertSame(3, $i); } - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testInt32AppendStringFail() - { - $arr = new RepeatedField(GPBType::INT32); - $arr []= 'abc'; - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testInt32SetStringFail() - { - $arr = new RepeatedField(GPBType::INT32); - $arr []= 0; - $arr [0]= 'abc'; - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testInt32AppendMessageFail() - { - $arr = new RepeatedField(GPBType::INT32); - $arr []= new TestMessage_Sub(); - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testInt32SetMessageFail() - { - $arr = new RepeatedField(GPBType::INT32); - $arr []= 0; - $arr [0]= new TestMessage_Sub(); - } - ######################################################### # Test uint32 field. ######################################################### @@ -124,31 +86,31 @@ class RepeatedFieldTest extends PHPUnit_Framework_TestCase $arr = new RepeatedField(GPBType::UINT32); // Test append. - $arr []= MAX_UINT32; + $arr[] = MAX_UINT32; $this->assertSame(-1, $arr[0]); - $arr []= -1; + $arr[] = -1; $this->assertSame(-1, $arr[1]); - $arr []= MIN_UINT32; + $arr[] = MIN_UINT32; $this->assertSame(MIN_UINT32, $arr[2]); - $arr []= 1.1; + $arr[] = 1.1; $this->assertSame(1, $arr[3]); - $arr []= MAX_UINT32_FLOAT; + $arr[] = MAX_UINT32_FLOAT; $this->assertSame(-1, $arr[4]); - $arr []= -1.0; + $arr[] = -1.0; $this->assertSame(-1, $arr[5]); - $arr []= MIN_UINT32_FLOAT; + $arr[] = MIN_UINT32_FLOAT; $this->assertSame(MIN_UINT32, $arr[6]); - $arr []= '2'; + $arr[] = '2'; $this->assertSame(2, $arr[7]); - $arr []= '3.1'; + $arr[] = '3.1'; $this->assertSame(3, $arr[8]); - $arr []= MAX_UINT32_STRING; + $arr[] = MAX_UINT32_STRING; $this->assertSame(-1, $arr[9]); - $arr []= '-1.0'; + $arr[] = '-1.0'; $this->assertSame(-1, $arr[10]); - $arr []= MIN_UINT32_STRING; + $arr[] = MIN_UINT32_STRING; $this->assertSame(MIN_UINT32, $arr[11]); $this->assertEquals(12, count($arr)); @@ -159,72 +121,34 @@ class RepeatedFieldTest extends PHPUnit_Framework_TestCase } // Test set. - $arr [0]= MAX_UINT32; + $arr[0] = MAX_UINT32; $this->assertSame(-1, $arr[0]); - $arr [1]= -1; + $arr[1] = -1; $this->assertSame(-1, $arr[1]); - $arr [2]= MIN_UINT32; + $arr[2] = MIN_UINT32; $this->assertSame(MIN_UINT32, $arr[2]); - $arr [3]= 1.1; + $arr[3] = 1.1; $this->assertSame(1, $arr[3]); - $arr [4]= MAX_UINT32_FLOAT; + $arr[4] = MAX_UINT32_FLOAT; $this->assertSame(-1, $arr[4]); - $arr [5]= -1.0; + $arr[5] = -1.0; $this->assertSame(-1, $arr[5]); - $arr [6]= MIN_UINT32_FLOAT; + $arr[6] = MIN_UINT32_FLOAT; $this->assertSame(MIN_UINT32, $arr[6]); - $arr [7]= '2'; + $arr[7] = '2'; $this->assertSame(2, $arr[7]); - $arr [8]= '3.1'; + $arr[8] = '3.1'; $this->assertSame(3, $arr[8]); - $arr [9]= MAX_UINT32_STRING; + $arr[9] = MAX_UINT32_STRING; $this->assertSame(-1, $arr[9]); - $arr [10]= '-1.0'; + $arr[10] = '-1.0'; $this->assertSame(-1, $arr[10]); - $arr [11]= MIN_UINT32_STRING; + $arr[11] = MIN_UINT32_STRING; $this->assertSame(MIN_UINT32, $arr[11]); } - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testUint32AppendStringFail() - { - $arr = new RepeatedField(GPBType::UINT32); - $arr []= 'abc'; - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testUint32SetStringFail() - { - $arr = new RepeatedField(GPBType::UINT32); - $arr []= 0; - $arr [0]= 'abc'; - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testUint32AppendMessageFail() - { - $arr = new RepeatedField(GPBType::UINT32); - $arr []= new TestMessage_Sub(); - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testUint32SetMessageFail() - { - $arr = new RepeatedField(GPBType::UINT32); - $arr []= 0; - $arr [0]= new TestMessage_Sub(); - } - ######################################################### # Test int64 field. ######################################################### @@ -234,13 +158,13 @@ class RepeatedFieldTest extends PHPUnit_Framework_TestCase $arr = new RepeatedField(GPBType::INT64); // Test append. - $arr []= MAX_INT64; - $arr []= MIN_INT64; - $arr []= 1.1; - $arr []= '2'; - $arr []= '3.1'; - $arr []= MAX_INT64_STRING; - $arr []= MIN_INT64_STRING; + $arr[] = MAX_INT64; + $arr[] = MIN_INT64; + $arr[] = 1.1; + $arr[] = '2'; + $arr[] = '3.1'; + $arr[] = MAX_INT64_STRING; + $arr[] = MIN_INT64_STRING; if (PHP_INT_SIZE == 4) { $this->assertSame(MAX_INT64, $arr[0]); $this->assertSame(MIN_INT64, $arr[1]); @@ -272,13 +196,13 @@ class RepeatedFieldTest extends PHPUnit_Framework_TestCase } // Test set. - $arr [0]= MAX_INT64; - $arr [1]= MIN_INT64; - $arr [2]= 1.1; - $arr [3]= '2'; - $arr [4]= '3.1'; - $arr [5]= MAX_INT64_STRING; - $arr [6]= MIN_INT64_STRING; + $arr[0] = MAX_INT64; + $arr[1] = MIN_INT64; + $arr[2] = 1.1; + $arr[3] = '2'; + $arr[4] = '3.1'; + $arr[5] = MAX_INT64_STRING; + $arr[6] = MIN_INT64_STRING; if (PHP_INT_SIZE == 4) { $this->assertSame(MAX_INT64_STRING, $arr[0]); @@ -299,44 +223,6 @@ class RepeatedFieldTest extends PHPUnit_Framework_TestCase } } - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testInt64AppendStringFail() - { - $arr = new RepeatedField(GPBType::INT64); - $arr []= 'abc'; - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testInt64SetStringFail() - { - $arr = new RepeatedField(GPBType::INT64); - $arr []= 0; - $arr [0]= 'abc'; - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testInt64AppendMessageFail() - { - $arr = new RepeatedField(GPBType::INT64); - $arr []= new TestMessage_Sub(); - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testInt64SetMessageFail() - { - $arr = new RepeatedField(GPBType::INT64); - $arr []= 0; - $arr [0]= new TestMessage_Sub(); - } - ######################################################### # Test uint64 field. ######################################################### @@ -346,11 +232,11 @@ class RepeatedFieldTest extends PHPUnit_Framework_TestCase $arr = new RepeatedField(GPBType::UINT64); // Test append. - $arr []= MAX_UINT64; - $arr []= 1.1; - $arr []= '2'; - $arr []= '3.1'; - $arr []= MAX_UINT64_STRING; + $arr[] = MAX_UINT64; + $arr[] = 1.1; + $arr[] = '2'; + $arr[] = '3.1'; + $arr[] = MAX_UINT64_STRING; if (PHP_INT_SIZE == 4) { $this->assertSame(MAX_UINT64_STRING, $arr[0]); @@ -379,11 +265,11 @@ class RepeatedFieldTest extends PHPUnit_Framework_TestCase } // Test set. - $arr [0]= MAX_UINT64; - $arr [1]= 1.1; - $arr [2]= '2'; - $arr [3]= '3.1'; - $arr [4]= MAX_UINT64_STRING; + $arr[0] = MAX_UINT64; + $arr[1] = 1.1; + $arr[2] = '2'; + $arr[3] = '3.1'; + $arr[4] = MAX_UINT64_STRING; if (PHP_INT_SIZE == 4) { $this->assertSame(MAX_UINT64_STRING, $arr[0]); @@ -400,44 +286,6 @@ class RepeatedFieldTest extends PHPUnit_Framework_TestCase } } - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testUint64AppendStringFail() - { - $arr = new RepeatedField(GPBType::UINT64); - $arr []= 'abc'; - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testUint64SetStringFail() - { - $arr = new RepeatedField(GPBType::UINT64); - $arr []= 0; - $arr [0]= 'abc'; - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testUint64AppendMessageFail() - { - $arr = new RepeatedField(GPBType::UINT64); - $arr []= new TestMessage_Sub(); - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testUint64SetMessageFail() - { - $arr = new RepeatedField(GPBType::UINT64); - $arr []= 0; - $arr [0]= new TestMessage_Sub(); - } - ######################################################### # Test float field. ######################################################### @@ -447,15 +295,15 @@ class RepeatedFieldTest extends PHPUnit_Framework_TestCase $arr = new RepeatedField(GPBType::FLOAT); // Test append. - $arr []= 1; + $arr[] = 1; $this->assertEquals(1.0, $arr[0], '', MAX_FLOAT_DIFF); - $arr []= 1.1; + $arr[] = 1.1; $this->assertEquals(1.1, $arr[1], '', MAX_FLOAT_DIFF); - $arr []= '2'; + $arr[] = '2'; $this->assertEquals(2.0, $arr[2], '', MAX_FLOAT_DIFF); - $arr []= '3.1'; + $arr[] = '3.1'; $this->assertEquals(3.1, $arr[3], '', MAX_FLOAT_DIFF); $this->assertEquals(4, count($arr)); @@ -466,56 +314,18 @@ class RepeatedFieldTest extends PHPUnit_Framework_TestCase } // Test set. - $arr [0]= 1; + $arr[0] = 1; $this->assertEquals(1.0, $arr[0], '', MAX_FLOAT_DIFF); - $arr [1]= 1.1; + $arr[1] = 1.1; $this->assertEquals(1.1, $arr[1], '', MAX_FLOAT_DIFF); - $arr [2]= '2'; + $arr[2] = '2'; $this->assertEquals(2.0, $arr[2], '', MAX_FLOAT_DIFF); - $arr [3]= '3.1'; + $arr[3] = '3.1'; $this->assertEquals(3.1, $arr[3], '', MAX_FLOAT_DIFF); } - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testFloatAppendStringFail() - { - $arr = new RepeatedField(GPBType::FLOAT); - $arr []= 'abc'; - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testFloatSetStringFail() - { - $arr = new RepeatedField(GPBType::FLOAT); - $arr []= 0.0; - $arr [0]= 'abc'; - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testFloatAppendMessageFail() - { - $arr = new RepeatedField(GPBType::FLOAT); - $arr []= new TestMessage_Sub(); - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testFloatSetMessageFail() - { - $arr = new RepeatedField(GPBType::FLOAT); - $arr []= 0.0; - $arr [0]= new TestMessage_Sub(); - } - ######################################################### # Test double field. ######################################################### @@ -525,15 +335,15 @@ class RepeatedFieldTest extends PHPUnit_Framework_TestCase $arr = new RepeatedField(GPBType::DOUBLE); // Test append. - $arr []= 1; + $arr[] = 1; $this->assertEquals(1.0, $arr[0], '', MAX_FLOAT_DIFF); - $arr []= 1.1; + $arr[] = 1.1; $this->assertEquals(1.1, $arr[1], '', MAX_FLOAT_DIFF); - $arr []= '2'; + $arr[] = '2'; $this->assertEquals(2.0, $arr[2], '', MAX_FLOAT_DIFF); - $arr []= '3.1'; + $arr[] = '3.1'; $this->assertEquals(3.1, $arr[3], '', MAX_FLOAT_DIFF); $this->assertEquals(4, count($arr)); @@ -544,56 +354,18 @@ class RepeatedFieldTest extends PHPUnit_Framework_TestCase } // Test set. - $arr [0]= 1; + $arr[0] = 1; $this->assertEquals(1.0, $arr[0], '', MAX_FLOAT_DIFF); - $arr [1]= 1.1; + $arr[1] = 1.1; $this->assertEquals(1.1, $arr[1], '', MAX_FLOAT_DIFF); - $arr [2]= '2'; + $arr[2] = '2'; $this->assertEquals(2.0, $arr[2], '', MAX_FLOAT_DIFF); - $arr [3]= '3.1'; + $arr[3] = '3.1'; $this->assertEquals(3.1, $arr[3], '', MAX_FLOAT_DIFF); } - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testDoubleAppendStringFail() - { - $arr = new RepeatedField(GPBType::DOUBLE); - $arr []= 'abc'; - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testDoubleSetStringFail() - { - $arr = new RepeatedField(GPBType::DOUBLE); - $arr []= 0.0; - $arr [0]= 'abc'; - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testDoubleAppendMessageFail() - { - $arr = new RepeatedField(GPBType::DOUBLE); - $arr []= new TestMessage_Sub(); - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testDoubleSetMessageFail() - { - $arr = new RepeatedField(GPBType::DOUBLE); - $arr []= 0.0; - $arr [0]= new TestMessage_Sub(); - } - ######################################################### # Test bool field. ######################################################### @@ -603,16 +375,16 @@ class RepeatedFieldTest extends PHPUnit_Framework_TestCase $arr = new RepeatedField(GPBType::BOOL); // Test append. - $arr []= true; + $arr[] = true; $this->assertSame(true, $arr[0]); - $arr []= -1; + $arr[] = -1; $this->assertSame(true, $arr[1]); - $arr []= 1.1; + $arr[] = 1.1; $this->assertSame(true, $arr[2]); - $arr []= ''; + $arr[] = ''; $this->assertSame(false, $arr[3]); $this->assertEquals(4, count($arr)); @@ -623,38 +395,19 @@ class RepeatedFieldTest extends PHPUnit_Framework_TestCase } // Test set. - $arr [0]= true; + $arr[0] = true; $this->assertSame(true, $arr[0]); - $arr [1]= -1; + $arr[1] = -1; $this->assertSame(true, $arr[1]); - $arr [2]= 1.1; + $arr[2] = 1.1; $this->assertSame(true, $arr[2]); - $arr [3]= ''; + $arr[3] = ''; $this->assertSame(false, $arr[3]); } - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testBoolAppendMessageFail() - { - $arr = new RepeatedField(GPBType::BOOL); - $arr []= new TestMessage_Sub(); - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testBoolSetMessageFail() - { - $arr = new RepeatedField(GPBType::BOOL); - $arr []= true; - $arr [0]= new TestMessage_Sub(); - } - ######################################################### # Test string field. ######################################################### @@ -664,16 +417,16 @@ class RepeatedFieldTest extends PHPUnit_Framework_TestCase $arr = new RepeatedField(GPBType::STRING); // Test append. - $arr []= 'abc'; + $arr[] = 'abc'; $this->assertSame('abc', $arr[0]); - $arr []= 1; + $arr[] = 1; $this->assertSame('1', $arr[1]); - $arr []= 1.1; + $arr[] = 1.1; $this->assertSame('1.1', $arr[2]); - $arr []= true; + $arr[] = true; $this->assertSame('1', $arr[3]); $this->assertEquals(4, count($arr)); @@ -684,59 +437,19 @@ class RepeatedFieldTest extends PHPUnit_Framework_TestCase } // Test set. - $arr [0]= 'abc'; + $arr[0] = 'abc'; $this->assertSame('abc', $arr[0]); - $arr [1]= 1; + $arr[1] = 1; $this->assertSame('1', $arr[1]); - $arr [2]= 1.1; + $arr[2] = 1.1; $this->assertSame('1.1', $arr[2]); - $arr [3]= true; + $arr[3] = true; $this->assertSame('1', $arr[3]); } - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testStringAppendMessageFail() - { - $arr = new RepeatedField(GPBType::STRING); - $arr []= new TestMessage_Sub(); - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testStringSetMessageFail() - { - $arr = new RepeatedField(GPBType::STRING); - $arr []= 'abc'; - $arr [0]= new TestMessage_Sub(); - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testStringAppendInvalidUTF8Fail() - { - $arr = new RepeatedField(GPBType::STRING); - $hex = hex2bin("ff"); - $arr []= $hex; - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testStringSetInvalidUTF8Fail() - { - $arr = new RepeatedField(GPBType::STRING); - $arr []= 'abc'; - $hex = hex2bin("ff"); - $arr [0]= $hex; - } - ######################################################### # Test message field. ######################################################### @@ -748,7 +461,7 @@ class RepeatedFieldTest extends PHPUnit_Framework_TestCase // Test append. $sub_m = new TestMessage_Sub(); $sub_m->setA(1); - $arr []= $sub_m; + $arr[] = $sub_m; $this->assertSame(1, $arr[0]->getA()); $this->assertEquals(1, count($arr)); @@ -756,78 +469,10 @@ class RepeatedFieldTest extends PHPUnit_Framework_TestCase // Test set. $sub_m = new TestMessage_Sub(); $sub_m->setA(2); - $arr [0]= $sub_m; + $arr[0] = $sub_m; $this->assertSame(2, $arr[0]->getA()); } - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testMessageAppendIntFail() - { - $arr = new RepeatedField(GPBType::MESSAGE, TestMessage_Sub::class); - $arr []= 1; - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testMessageSetIntFail() - { - $arr = new RepeatedField(GPBType::MESSAGE, TestMessage_Sub::class); - $arr []= new TestMessage_Sub; - $arr [0]= 'abc'; - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testMessageAppendStringFail() - { - $arr = new RepeatedField(GPBType::MESSAGE, TestMessage_Sub::class); - $arr []= 'abc'; - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testMessageSetStringFail() - { - $arr = new RepeatedField(GPBType::MESSAGE, TestMessage_Sub::class); - $arr []= new TestMessage_Sub; - $arr [0]= 'abc'; - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testMessageAppendOtherMessageFail() - { - $arr = new RepeatedField(GPBType::MESSAGE, TestMessage_Sub::class); - $arr []= new TestMessage; - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testMessageAppendNullFail() - { - $arr = new RepeatedField(GPBType::MESSAGE, TestMessage_Sub::class); - $null = null; - $arr []= $null; - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testMessageSetNullFail() - { - $arr = new RepeatedField(GPBType::MESSAGE, TestMessage_Sub::class); - $arr []= new TestMessage_Sub(); - $null = null; - $arr[0] = $null; - } - ######################################################### # Test offset type ######################################################### @@ -835,18 +480,18 @@ class RepeatedFieldTest extends PHPUnit_Framework_TestCase public function testOffset() { $arr = new RepeatedField(GPBType::INT32); - $arr []= 0; + $arr[] = 0; - $arr [0]= 1; + $arr[0] = 1; $this->assertSame(1, $arr[0]); $this->assertSame(1, count($arr)); - $arr ['0']= 2; + $arr['0'] = 2; $this->assertSame(2, $arr['0']); $this->assertSame(2, $arr[0]); $this->assertSame(1, count($arr)); - $arr [0.0]= 3; + $arr[0.0] = 3; $this->assertSame(3, $arr[0.0]); $this->assertSame(1, count($arr)); } @@ -855,9 +500,9 @@ class RepeatedFieldTest extends PHPUnit_Framework_TestCase { $arr = new RepeatedField(GPBType::INT32); - $arr []= 0; - $arr []= 1; - $arr []= 2; + $arr[] = 0; + $arr[] = 1; + $arr[] = 2; $this->assertSame(3, count($arr)); unset($arr[2]); @@ -865,67 +510,13 @@ class RepeatedFieldTest extends PHPUnit_Framework_TestCase $this->assertSame(0, $arr[0]); $this->assertSame(1, $arr[1]); - $arr [] = 3; + $arr[] = 3; $this->assertSame(3, count($arr)); $this->assertSame(0, $arr[0]); $this->assertSame(1, $arr[1]); $this->assertSame(3, $arr[2]); } - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testRemoveMiddleFail() - { - $arr = new RepeatedField(GPBType::INT32); - - $arr []= 0; - $arr []= 1; - $arr []= 2; - $this->assertSame(3, count($arr)); - - unset($arr[1]); - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testRemoveEmptyFail() - { - $arr = new RepeatedField(GPBType::INT32); - - unset($arr[0]); - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testMessageOffsetFail() - { - $arr = new RepeatedField(GPBType::INT32); - $arr []= 0; - $arr [new TestMessage_Sub()]= 0; - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testStringOffsetFail() - { - $arr = new RepeatedField(GPBType::INT32); - $arr []= 0; - $arr ['abc']= 0; - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testSetNonExistedOffsetFail() - { - $arr = new RepeatedField(GPBType::INT32); - $arr [0]= 0; - } - ######################################################### # Test memory leak ######################################################### @@ -933,7 +524,7 @@ class RepeatedFieldTest extends PHPUnit_Framework_TestCase public function testCycleLeak() { $arr = new RepeatedField(GPBType::MESSAGE, TestMessage::class); - $arr []= new TestMessage; + $arr[] = new TestMessage; $arr[0]->SetRepeatedRecursive($arr); // Clean up memory before test. |