diff options
author | Jisi Liu <jisi.liu@gmail.com> | 2017-07-18 16:26:16 -0700 |
---|---|---|
committer | Jisi Liu <jisi.liu@gmail.com> | 2017-07-18 16:26:16 -0700 |
commit | 3af881c7e2db0553207876acbdb91c6e77974e44 (patch) | |
tree | 35e2a96cce802d4235bd29afa396e28ead892fa2 /php/tests/map_field_test.php | |
parent | 86975301f1876ce1934612777b8ca6c76520f5cc (diff) | |
parent | 942a29cecd36f2a4b22fdd2179635cd548e6bd27 (diff) | |
download | protobuf-3af881c7e2db0553207876acbdb91c6e77974e44.tar.gz protobuf-3af881c7e2db0553207876acbdb91c6e77974e44.tar.bz2 protobuf-3af881c7e2db0553207876acbdb91c6e77974e44.zip |
Merge master into 3.4.x
Diffstat (limited to 'php/tests/map_field_test.php')
-rw-r--r-- | php/tests/map_field_test.php | 303 |
1 files changed, 31 insertions, 272 deletions
diff --git a/php/tests/map_field_test.php b/php/tests/map_field_test.php index 2fda9135..120b1bde 100644 --- a/php/tests/map_field_test.php +++ b/php/tests/map_field_test.php @@ -56,42 +56,23 @@ class MapFieldTest extends PHPUnit_Framework_TestCase { unset($arr['3.1']); unset($arr[MAX_INT32_STRING]); $this->assertEquals(0, count($arr)); - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testInt32SetStringKeyFail() - { - $arr = new MapField(GPBType::INT32, GPBType::INT32); - $arr ['abc']= 0; - } - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testInt32SetStringValueFail() - { + // Test foreach. $arr = new MapField(GPBType::INT32, GPBType::INT32); - $arr [0]= 'abc'; - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testInt32SetMessageKeyFail() - { - $arr = new MapField(GPBType::INT32, GPBType::INT32); - $arr [new TestMessage_Sub()]= 0; - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testInt32SetMessageValueFail() - { - $arr = new MapField(GPBType::INT32, GPBType::INT32); - $arr [0]= new TestMessage_Sub(); + 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); } ######################################################### @@ -159,42 +140,6 @@ class MapFieldTest extends PHPUnit_Framework_TestCase { $this->assertEquals(0, count($arr)); } - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testUint32SetStringKeyFail() - { - $arr = new MapField(GPBType::UINT32, GPBType::UINT32); - $arr ['abc']= 0; - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testUint32SetStringValueFail() - { - $arr = new MapField(GPBType::UINT32, GPBType::UINT32); - $arr [0]= 'abc'; - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testUint32SetMessageKeyFail() - { - $arr = new MapField(GPBType::UINT32, GPBType::UINT32); - $arr [new TestMessage_Sub()]= 0; - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testUint32SetMessageValueFail() - { - $arr = new MapField(GPBType::UINT32, GPBType::UINT32); - $arr [0]= new TestMessage_Sub(); - } - ######################################################### # Test int64 field. ######################################################### @@ -252,42 +197,6 @@ class MapFieldTest extends PHPUnit_Framework_TestCase { $this->assertEquals(0, count($arr)); } - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testInt64SetStringKeyFail() - { - $arr = new MapField(GPBType::INT64, GPBType::INT64); - $arr ['abc']= 0; - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testInt64SetStringValueFail() - { - $arr = new MapField(GPBType::INT64, GPBType::INT64); - $arr [0]= 'abc'; - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testInt64SetMessageKeyFail() - { - $arr = new MapField(GPBType::INT64, GPBType::INT64); - $arr [new TestMessage_Sub()]= 0; - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testInt64SetMessageValueFail() - { - $arr = new MapField(GPBType::INT64, GPBType::INT64); - $arr [0]= new TestMessage_Sub(); - } - ######################################################### # Test uint64 field. ######################################################### @@ -339,42 +248,6 @@ class MapFieldTest extends PHPUnit_Framework_TestCase { $this->assertEquals(0, count($arr)); } - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testUint64SetStringKeyFail() - { - $arr = new MapField(GPBType::UINT64, GPBType::UINT64); - $arr ['abc']= 0; - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testUint64SetStringValueFail() - { - $arr = new MapField(GPBType::UINT64, GPBType::UINT64); - $arr [0]= 'abc'; - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testUint64SetMessageKeyFail() - { - $arr = new MapField(GPBType::UINT64, GPBType::UINT64); - $arr [new TestMessage_Sub()]= 0; - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testUint64SetMessageValueFail() - { - $arr = new MapField(GPBType::UINT64, GPBType::UINT64); - $arr [0]= new TestMessage_Sub(); - } - ######################################################### # Test float field. ######################################################### @@ -397,24 +270,6 @@ class MapFieldTest extends PHPUnit_Framework_TestCase { $this->assertEquals(4, count($arr)); } - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testFloatSetStringValueFail() - { - $arr = new MapField(GPBType::INT64, GPBType::FLOAT); - $arr [0]= 'abc'; - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testFloatSetMessageValueFail() - { - $arr = new MapField(GPBType::INT64, GPBType::FLOAT); - $arr [0]= new TestMessage_Sub(); - } - ######################################################### # Test double field. ######################################################### @@ -437,24 +292,6 @@ class MapFieldTest extends PHPUnit_Framework_TestCase { $this->assertEquals(4, count($arr)); } - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testDoubleSetStringValueFail() - { - $arr = new MapField(GPBType::INT64, GPBType::DOUBLE); - $arr [0]= 'abc'; - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testDoubleSetMessageValueFail() - { - $arr = new MapField(GPBType::INT64, GPBType::DOUBLE); - $arr [0]= new TestMessage_Sub(); - } - ######################################################### # Test bool field. ######################################################### @@ -515,24 +352,6 @@ class MapFieldTest extends PHPUnit_Framework_TestCase { $this->assertEquals(0, count($arr)); } - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testBoolSetMessageKeyFail() - { - $arr = new MapField(GPBType::BOOL, GPBType::BOOL); - $arr [new TestMessage_Sub()]= true; - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testBoolSetMessageValueFail() - { - $arr = new MapField(GPBType::BOOL, GPBType::BOOL); - $arr [true]= new TestMessage_Sub(); - } - ######################################################### # Test string field. ######################################################### @@ -564,42 +383,23 @@ class MapFieldTest extends PHPUnit_Framework_TestCase { $this->assertEquals(1, count($arr)); unset($arr[True]); $this->assertEquals(0, count($arr)); - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testStringSetInvalidUTF8KeyFail() - { - $arr = new MapField(GPBType::STRING, GPBType::STRING); - $arr[hex2bin("ff")]= 'abc'; - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testStringSetInvalidUTF8ValueFail() - { - $arr = new MapField(GPBType::STRING, GPBType::STRING); - $arr ['abc']= hex2bin("ff"); - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testStringSetMessageKeyFail() - { - $arr = new MapField(GPBType::STRING, GPBType::STRING); - $arr [new TestMessage_Sub()]= 'abc'; - } - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testStringSetMessageValueFail() - { + // Test foreach. $arr = new MapField(GPBType::STRING, GPBType::STRING); - $arr ['abc']= new TestMessage_Sub(); + 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); } ######################################################### @@ -619,47 +419,6 @@ class MapFieldTest extends PHPUnit_Framework_TestCase { $this->assertEquals(1, count($arr)); } - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testMessageSetIntValueFail() - { - $arr = - new MapField(GPBType::INT32, GPBType::MESSAGE, TestMessage::class); - $arr[0] = 0; - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testMessageSetStringValueFail() - { - $arr = - new MapField(GPBType::INT32, GPBType::MESSAGE, TestMessage::class); - $arr[0] = 'abc'; - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testMessageSetOtherMessageValueFail() - { - $arr = - new MapField(GPBType::INT32, GPBType::MESSAGE, TestMessage::class); - $arr[0] = new TestMessage_Sub(); - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testMessageSetNullFail() - { - $arr = - new MapField(GPBType::INT32, GPBType::MESSAGE, TestMessage::class); - $null = NULL; - $arr[0] = $null; - } - ######################################################### # Test memory leak ######################################################### @@ -669,7 +428,7 @@ class MapFieldTest extends PHPUnit_Framework_TestCase { // { // $arr = new MapField(GPBType::INT32, // GPBType::MESSAGE, TestMessage::class); - // $arr [0]= new TestMessage; + // $arr[0] = new TestMessage; // $arr[0]->SetMapRecursive($arr); // // Clean up memory before test. |