Browse Source

added tests for hasOneof<Field>() php methods

Andrei Nigmatulin 4 năm trước cách đây
mục cha
commit
52d3be3276
4 tập tin đã thay đổi với 29 bổ sung2 xóa
  1. 1 1
      php/ext/google/protobuf/message.c
  2. 1 0
      php/phpunit.xml
  3. 26 0
      php/tests/HasOneofTest.php
  4. 1 1
      php/tests/test.sh

+ 1 - 1
php/ext/google/protobuf/message.c

@@ -907,7 +907,7 @@ PHP_METHOD(Message, whichOneof) {
 /**
  * Message::hasOneof()
  *
- * Returns the presense of the given oneof field, given a field number. Called
+ * Returns the presence of the given oneof field, given a field number. Called
  * from generated code methods such as:
  *
  *    public function hasDoubleValueOneof()

+ 1 - 0
php/phpunit.xml

@@ -13,6 +13,7 @@
       <file>tests/DescriptorsTest.php</file>
       <file>tests/GeneratedServiceTest.php</file>
       <file>tests/WrapperTypeSettersTest.php</file>
+      <file>tests/HasOneofTest.php</file>
     </testsuite>
   </testsuites>
 </phpunit>

+ 26 - 0
php/tests/HasOneofTest.php

@@ -0,0 +1,26 @@
+<?php
+
+require_once('test_util.php');
+
+use Foo\TestMessage;
+
+class HasOneofTest extends \PHPUnit\Framework\TestCase {
+
+    #########################################################
+    # Test hasOneof<Field> methods exists and working
+    #########################################################
+
+    public function testHasOneof() {
+        $m = new TestMessage();
+        $this->assertFalse($m->hasOneofInt32());
+        $m->setOneofInt32(42);
+        $this->assertTrue($m->hasOneofInt32());
+        $m->setOneofString("bar");
+        $this->assertFalse($m->hasOneofInt32());
+        $this->assertTrue($m->hasOneofString());
+        $m->clear();
+        $this->assertFalse($m->hasOneofInt32());
+        $this->assertFalse($m->hasOneofString());
+    }
+
+}

+ 1 - 1
php/tests/test.sh

@@ -29,7 +29,7 @@ esac
 
 [ -f $PHPUNIT ] || wget https://phar.phpunit.de/$PHPUNIT
 
-tests=( ArrayTest.php EncodeDecodeTest.php GeneratedClassTest.php MapFieldTest.php WellKnownTest.php DescriptorsTest.php WrapperTypeSettersTest.php)
+tests=( ArrayTest.php EncodeDecodeTest.php GeneratedClassTest.php MapFieldTest.php WellKnownTest.php DescriptorsTest.php WrapperTypeSettersTest.php HasOneofTest.php)
 
 for t in "${tests[@]}"
 do