From 190b5270c8717ca343db42da489e5e7d6d9efb2c Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Wed, 19 Apr 2017 16:23:51 -0700 Subject: Make PHP c extension work with PHP7 (#2951) --- php/tests/array_test.php | 39 +++++++++++++++++++++++++-------------- php/tests/gdb_test.sh | 8 +++----- php/tests/map_field_test.php | 17 ++++++++++++----- php/tests/memory_leak_test.php | 9 +++++---- php/tests/test_util.php | 3 +-- 5 files changed, 46 insertions(+), 30 deletions(-) (limited to 'php/tests') diff --git a/php/tests/array_test.php b/php/tests/array_test.php index a4cad719..b55408da 100644 --- a/php/tests/array_test.php +++ b/php/tests/array_test.php @@ -751,23 +751,13 @@ class RepeatedFieldTest extends PHPUnit_Framework_TestCase $arr []= $sub_m; $this->assertSame(1, $arr[0]->getA()); - $null = null; - $arr []= $null; - $this->assertNull($arr[1]); - - $this->assertEquals(2, count($arr)); - - for ($i = 0; $i < count($arr); $i++) { - $arr[$i] = $null; - $this->assertNull($arr[$i]); - } + $this->assertEquals(1, count($arr)); // Test set. + $sub_m = new TestMessage_Sub(); + $sub_m->setA(2); $arr [0]= $sub_m; - $this->assertSame(1, $arr[0]->getA()); - - $arr [1]= $null; - $this->assertNull($arr[1]); + $this->assertSame(2, $arr[0]->getA()); } /** @@ -817,6 +807,27 @@ class RepeatedFieldTest extends PHPUnit_Framework_TestCase $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 ######################################################### diff --git a/php/tests/gdb_test.sh b/php/tests/gdb_test.sh index 45a2841f..484e2edf 100755 --- a/php/tests/gdb_test.sh +++ b/php/tests/gdb_test.sh @@ -3,10 +3,8 @@ # gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so `which # phpunit` --bootstrap autoload.php tmp_test.php # -gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so `which phpunit` --bootstrap autoload.php array_test.php +gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so `which phpunit` --bootstrap autoload.php encode_decode_test.php # -# # gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so -# memory_leak_test.php +# gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so memory_leak_test.php # -# # USE_ZEND_ALLOC=0 valgrind --leak-check=yes php -# -dextension=../ext/google/protobuf/modules/protobuf.so memory_leak_test.php +# USE_ZEND_ALLOC=0 valgrind --leak-check=yes php -dextension=../ext/google/protobuf/modules/protobuf.so memory_leak_test.php diff --git a/php/tests/map_field_test.php b/php/tests/map_field_test.php index d4ec44fc..2fda9135 100644 --- a/php/tests/map_field_test.php +++ b/php/tests/map_field_test.php @@ -616,11 +616,7 @@ class MapFieldTest extends PHPUnit_Framework_TestCase { $arr[0] = $sub_m; $this->assertSame(1, $arr[0]->getA()); - $null = NULL; - $arr[1] = $null; - $this->assertNull($arr[1]); - - $this->assertEquals(2, count($arr)); + $this->assertEquals(1, count($arr)); } /** @@ -653,6 +649,17 @@ class MapFieldTest extends PHPUnit_Framework_TestCase { $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 ######################################################### diff --git a/php/tests/memory_leak_test.php b/php/tests/memory_leak_test.php index 5dd79519..68b6f5be 100644 --- a/php/tests/memory_leak_test.php +++ b/php/tests/memory_leak_test.php @@ -83,7 +83,8 @@ $n = new TestMessage(); $n->mergeFromString($data); assert(1 === $n->getOneofMessage()->getA()); -$from = new TestMessage(); -$to = new TestMessage(); -TestUtil::setTestMessage($from); -$to->mergeFrom($from); +# $from = new TestMessage(); +# $to = new TestMessage(); +# TestUtil::setTestMessage($from); +# $to->mergeFrom($from); +# TestUtil::assertTestMessage($to); diff --git a/php/tests/test_util.php b/php/tests/test_util.php index 61f94aa1..9dbcbb62 100644 --- a/php/tests/test_util.php +++ b/php/tests/test_util.php @@ -51,8 +51,6 @@ class TestUtil public static function setTestMessage(TestMessage $m) { - $sub = new TestMessage_Sub(); - $m->setOptionalInt32(-42); $m->setOptionalInt64(-43); $m->setOptionalUint32(42); @@ -69,6 +67,7 @@ class TestUtil $m->setOptionalString('a'); $m->setOptionalBytes('b'); $m->setOptionalEnum(TestEnum::ONE); + $sub = new TestMessage_Sub(); $m->setOptionalMessage($sub); $m->getOptionalMessage()->SetA(33); -- cgit v1.2.3