From 52d3be327632d2e2c7c489ee44c917b2f795eff5 Mon Sep 17 00:00:00 2001 From: Andrei Nigmatulin Date: Tue, 3 Nov 2020 12:17:25 +0000 Subject: [PATCH] added tests for hasOneof() php methods --- php/ext/google/protobuf/message.c | 2 +- php/phpunit.xml | 1 + php/tests/HasOneofTest.php | 26 ++++++++++++++++++++++++++ php/tests/test.sh | 2 +- 4 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 php/tests/HasOneofTest.php diff --git a/php/ext/google/protobuf/message.c b/php/ext/google/protobuf/message.c index ec0349ea8c..f15b8ac1b4 100644 --- a/php/ext/google/protobuf/message.c +++ b/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() diff --git a/php/phpunit.xml b/php/phpunit.xml index 8e7583596b..f00d4a3d12 100644 --- a/php/phpunit.xml +++ b/php/phpunit.xml @@ -13,6 +13,7 @@ tests/DescriptorsTest.php tests/GeneratedServiceTest.php tests/WrapperTypeSettersTest.php + tests/HasOneofTest.php diff --git a/php/tests/HasOneofTest.php b/php/tests/HasOneofTest.php new file mode 100644 index 0000000000..e7f8954bfd --- /dev/null +++ b/php/tests/HasOneofTest.php @@ -0,0 +1,26 @@ + 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()); + } + +} diff --git a/php/tests/test.sh b/php/tests/test.sh index 91ea56ec8f..f693fe6127 100755 --- a/php/tests/test.sh +++ b/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