aboutsummaryrefslogtreecommitdiff
path: root/php/tests
diff options
context:
space:
mode:
Diffstat (limited to 'php/tests')
-rwxr-xr-xphp/tests/compatibility_test.sh3
-rw-r--r--php/tests/encode_decode_test.php81
-rw-r--r--php/tests/memory_leak_test.php2
-rw-r--r--php/tests/undefined_test.php2
-rw-r--r--php/tests/well_known_test.php4
5 files changed, 88 insertions, 4 deletions
diff --git a/php/tests/compatibility_test.sh b/php/tests/compatibility_test.sh
index b377d85c..dc8de5dc 100755
--- a/php/tests/compatibility_test.sh
+++ b/php/tests/compatibility_test.sh
@@ -92,7 +92,7 @@ echo "Running compatibility tests between $VERSION_NUMBER and $OLD_VERSION"
# Download old test.
rm -rf protobuf
-git clone https://github.com/google/protobuf.git
+git clone https://github.com/protocolbuffers/protobuf.git
pushd protobuf
git checkout v$OLD_VERSION
popd
@@ -124,6 +124,7 @@ sed -i.bak '/php_implementation_test.php/d' phpunit.xml
sed -i.bak '/generated_phpdoc_test.php/d' phpunit.xml
sed -i.bak 's/generated_phpdoc_test.php//g' tests/test.sh
sed -i.bak '/memory_leak_test.php/d' tests/test.sh
+sed -i.bak '/^ public function testTimestamp()$/,/^ }$/d' tests/well_known_test.php
for t in "${tests[@]}"
do
remove_error_test tests/$t
diff --git a/php/tests/encode_decode_test.php b/php/tests/encode_decode_test.php
index d36b883e..870dacab 100644
--- a/php/tests/encode_decode_test.php
+++ b/php/tests/encode_decode_test.php
@@ -11,9 +11,90 @@ use Foo\TestMessage\Sub;
use Foo\TestPackedMessage;
use Foo\TestRandomFieldOrder;
use Foo\TestUnpackedMessage;
+use Google\Protobuf\DoubleValue;
+use Google\Protobuf\FloatValue;
+use Google\Protobuf\Int32Value;
+use Google\Protobuf\UInt32Value;
+use Google\Protobuf\Int64Value;
+use Google\Protobuf\UInt64Value;
+use Google\Protobuf\BoolValue;
+use Google\Protobuf\StringValue;
+use Google\Protobuf\BytesValue;
class EncodeDecodeTest extends TestBase
{
+ public function testDecodeJsonSimple()
+ {
+ $m = new TestMessage();
+ $m->mergeFromJsonString("{\"optionalInt32\":1}");
+ }
+
+ public function testDecodeTopLevelBoolValue()
+ {
+ $m = new BoolValue();
+
+ $m->mergeFromJsonString("true");
+ $this->assertEquals(true, $m->getValue());
+
+ $m->mergeFromJsonString("false");
+ $this->assertEquals(false, $m->getValue());
+ }
+
+ public function testDecodeTopLevelDoubleValue()
+ {
+ $m = new DoubleValue();
+ $m->mergeFromJsonString("1.5");
+ $this->assertEquals(1.5, $m->getValue());
+ }
+
+ public function testDecodeTopLevelFloatValue()
+ {
+ $m = new FloatValue();
+ $m->mergeFromJsonString("1.5");
+ $this->assertEquals(1.5, $m->getValue());
+ }
+
+ public function testDecodeTopLevelInt32Value()
+ {
+ $m = new Int32Value();
+ $m->mergeFromJsonString("1");
+ $this->assertEquals(1, $m->getValue());
+ }
+
+ public function testDecodeTopLevelUInt32Value()
+ {
+ $m = new UInt32Value();
+ $m->mergeFromJsonString("1");
+ $this->assertEquals(1, $m->getValue());
+ }
+
+ public function testDecodeTopLevelInt64Value()
+ {
+ $m = new Int64Value();
+ $m->mergeFromJsonString("1");
+ $this->assertEquals(1, $m->getValue());
+ }
+
+ public function testDecodeTopLevelUInt64Value()
+ {
+ $m = new UInt64Value();
+ $m->mergeFromJsonString("1");
+ $this->assertEquals(1, $m->getValue());
+ }
+
+ public function testDecodeTopLevelStringValue()
+ {
+ $m = new StringValue();
+ $m->mergeFromJsonString("\"a\"");
+ $this->assertSame("a", $m->getValue());
+ }
+
+ public function testDecodeTopLevelBytesValue()
+ {
+ $m = new BytesValue();
+ $m->mergeFromJsonString("\"YQ==\"");
+ $this->assertSame("a", $m->getValue());
+ }
public function testEncode()
{
diff --git a/php/tests/memory_leak_test.php b/php/tests/memory_leak_test.php
index 4e3874b7..f3bcb963 100644
--- a/php/tests/memory_leak_test.php
+++ b/php/tests/memory_leak_test.php
@@ -152,7 +152,7 @@ date_default_timezone_set('UTC');
$from = new DateTime('2011-01-01T15:03:01.012345UTC');
$timestamp->fromDateTime($from);
assert($from->format('U') == $timestamp->getSeconds());
-assert(0 == $timestamp->getNanos());
+assert(1000 * $from->format('u') == $timestamp->getNanos());
$to = $timestamp->toDateTime();
assert(\DateTime::class == get_class($to));
diff --git a/php/tests/undefined_test.php b/php/tests/undefined_test.php
index f8444571..935d8be7 100644
--- a/php/tests/undefined_test.php
+++ b/php/tests/undefined_test.php
@@ -909,7 +909,7 @@ class UndefinedTest extends PHPUnit_Framework_TestCase
/**
* @expectedException PHPUnit_Framework_Error
*/
- public function testMessageSetNullFail()
+ public function testMessageSetNullFailMap()
{
$arr =
new MapField(GPBType::INT32, GPBType::MESSAGE, TestMessage::class);
diff --git a/php/tests/well_known_test.php b/php/tests/well_known_test.php
index 1e8c4f42..6a788df2 100644
--- a/php/tests/well_known_test.php
+++ b/php/tests/well_known_test.php
@@ -42,6 +42,7 @@ class WellKnownTest extends TestBase {
public function testEmpty()
{
$msg = new GPBEmpty();
+ $this->assertTrue($msg instanceof \Google\Protobuf\Internal\Message);
}
public function testImportDescriptorProto()
@@ -312,11 +313,12 @@ class WellKnownTest extends TestBase {
$from = new DateTime('2011-01-01T15:03:01.012345UTC');
$timestamp->fromDateTime($from);
$this->assertEquals($from->format('U'), $timestamp->getSeconds());
- $this->assertSame(0, $timestamp->getNanos());
+ $this->assertEquals(1000 * $from->format('u'), $timestamp->getNanos());
$to = $timestamp->toDateTime();
$this->assertSame(\DateTime::class, get_class($to));
$this->assertSame($from->format('U'), $to->format('U'));
+ $this->assertSame($from->format('u'), $to->format('u'));
}
public function testType()