aboutsummaryrefslogtreecommitdiffhomepage
path: root/php/tests
diff options
context:
space:
mode:
authorGravatar Paul Yang <TeBoring@users.noreply.github.com>2017-04-19 16:23:51 -0700
committerGravatar GitHub <noreply@github.com>2017-04-19 16:23:51 -0700
commit190b5270c8717ca343db42da489e5e7d6d9efb2c (patch)
tree3815f20268bc56aac88267004149f9e4eb634223 /php/tests
parent43234828da6ae3a3a3ada25d11488fdfd080b79c (diff)
Make PHP c extension work with PHP7 (#2951)
Diffstat (limited to 'php/tests')
-rw-r--r--php/tests/array_test.php39
-rwxr-xr-xphp/tests/gdb_test.sh8
-rw-r--r--php/tests/map_field_test.php17
-rw-r--r--php/tests/memory_leak_test.php9
-rw-r--r--php/tests/test_util.php3
5 files changed, 46 insertions, 30 deletions
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);