1ffe3c632Sopenharmony_ci<?php 2ffe3c632Sopenharmony_ci 3ffe3c632Sopenharmony_cirequire_once('test_base.php'); 4ffe3c632Sopenharmony_cirequire_once('test_util.php'); 5ffe3c632Sopenharmony_ci 6ffe3c632Sopenharmony_ciuse Foo\TestMessage; 7ffe3c632Sopenharmony_ciuse Foo\TestImportDescriptorProto; 8ffe3c632Sopenharmony_ciuse Google\Protobuf\Any; 9ffe3c632Sopenharmony_ciuse Google\Protobuf\Api; 10ffe3c632Sopenharmony_ciuse Google\Protobuf\BoolValue; 11ffe3c632Sopenharmony_ciuse Google\Protobuf\BytesValue; 12ffe3c632Sopenharmony_ciuse Google\Protobuf\DoubleValue; 13ffe3c632Sopenharmony_ciuse Google\Protobuf\Duration; 14ffe3c632Sopenharmony_ciuse Google\Protobuf\Enum; 15ffe3c632Sopenharmony_ciuse Google\Protobuf\EnumValue; 16ffe3c632Sopenharmony_ciuse Google\Protobuf\Field; 17ffe3c632Sopenharmony_ciuse Google\Protobuf\FieldMask; 18ffe3c632Sopenharmony_ciuse Google\Protobuf\Field\Cardinality; 19ffe3c632Sopenharmony_ciuse Google\Protobuf\Field\Kind; 20ffe3c632Sopenharmony_ciuse Google\Protobuf\FloatValue; 21ffe3c632Sopenharmony_ciuse Google\Protobuf\GPBEmpty; 22ffe3c632Sopenharmony_ciuse Google\Protobuf\Int32Value; 23ffe3c632Sopenharmony_ciuse Google\Protobuf\Int64Value; 24ffe3c632Sopenharmony_ciuse Google\Protobuf\ListValue; 25ffe3c632Sopenharmony_ciuse Google\Protobuf\Method; 26ffe3c632Sopenharmony_ciuse Google\Protobuf\Mixin; 27ffe3c632Sopenharmony_ciuse Google\Protobuf\NullValue; 28ffe3c632Sopenharmony_ciuse Google\Protobuf\Option; 29ffe3c632Sopenharmony_ciuse Google\Protobuf\SourceContext; 30ffe3c632Sopenharmony_ciuse Google\Protobuf\StringValue; 31ffe3c632Sopenharmony_ciuse Google\Protobuf\Struct; 32ffe3c632Sopenharmony_ciuse Google\Protobuf\Syntax; 33ffe3c632Sopenharmony_ciuse Google\Protobuf\Timestamp; 34ffe3c632Sopenharmony_ciuse Google\Protobuf\Type; 35ffe3c632Sopenharmony_ciuse Google\Protobuf\UInt32Value; 36ffe3c632Sopenharmony_ciuse Google\Protobuf\UInt64Value; 37ffe3c632Sopenharmony_ciuse Google\Protobuf\Value; 38ffe3c632Sopenharmony_ci 39ffe3c632Sopenharmony_ciclass NotMessage {} 40ffe3c632Sopenharmony_ci 41ffe3c632Sopenharmony_ciclass WellKnownTest extends TestBase { 42ffe3c632Sopenharmony_ci 43ffe3c632Sopenharmony_ci public function testEmpty() 44ffe3c632Sopenharmony_ci { 45ffe3c632Sopenharmony_ci $msg = new GPBEmpty(); 46ffe3c632Sopenharmony_ci $this->assertTrue($msg instanceof \Google\Protobuf\Internal\Message); 47ffe3c632Sopenharmony_ci } 48ffe3c632Sopenharmony_ci 49ffe3c632Sopenharmony_ci public function testImportDescriptorProto() 50ffe3c632Sopenharmony_ci { 51ffe3c632Sopenharmony_ci $msg = new TestImportDescriptorProto(); 52ffe3c632Sopenharmony_ci $this->assertTrue(true); 53ffe3c632Sopenharmony_ci } 54ffe3c632Sopenharmony_ci 55ffe3c632Sopenharmony_ci public function testAny() 56ffe3c632Sopenharmony_ci { 57ffe3c632Sopenharmony_ci // Create embed message 58ffe3c632Sopenharmony_ci $embed = new TestMessage(); 59ffe3c632Sopenharmony_ci $this->setFields($embed); 60ffe3c632Sopenharmony_ci $data = $embed->serializeToString(); 61ffe3c632Sopenharmony_ci 62ffe3c632Sopenharmony_ci // Set any via normal setter. 63ffe3c632Sopenharmony_ci $any = new Any(); 64ffe3c632Sopenharmony_ci 65ffe3c632Sopenharmony_ci $this->assertSame( 66ffe3c632Sopenharmony_ci $any, $any->setTypeUrl("type.googleapis.com/foo.TestMessage")); 67ffe3c632Sopenharmony_ci $this->assertSame("type.googleapis.com/foo.TestMessage", 68ffe3c632Sopenharmony_ci $any->getTypeUrl()); 69ffe3c632Sopenharmony_ci 70ffe3c632Sopenharmony_ci $this->assertSame($any, $any->setValue($data)); 71ffe3c632Sopenharmony_ci $this->assertSame($data, $any->getValue()); 72ffe3c632Sopenharmony_ci 73ffe3c632Sopenharmony_ci // Test unpack. 74ffe3c632Sopenharmony_ci $msg = $any->unpack(); 75ffe3c632Sopenharmony_ci $this->assertTrue($msg instanceof TestMessage); 76ffe3c632Sopenharmony_ci $this->expectFields($msg); 77ffe3c632Sopenharmony_ci 78ffe3c632Sopenharmony_ci // Test pack. 79ffe3c632Sopenharmony_ci $any = new Any(); 80ffe3c632Sopenharmony_ci $any->pack($embed); 81ffe3c632Sopenharmony_ci $this->assertSame($data, $any->getValue()); 82ffe3c632Sopenharmony_ci $this->assertSame("type.googleapis.com/foo.TestMessage", $any->getTypeUrl()); 83ffe3c632Sopenharmony_ci 84ffe3c632Sopenharmony_ci // Test is. 85ffe3c632Sopenharmony_ci $this->assertTrue($any->is(TestMessage::class)); 86ffe3c632Sopenharmony_ci $this->assertFalse($any->is(Any::class)); 87ffe3c632Sopenharmony_ci } 88ffe3c632Sopenharmony_ci 89ffe3c632Sopenharmony_ci /** 90ffe3c632Sopenharmony_ci * @expectedException Exception 91ffe3c632Sopenharmony_ci */ 92ffe3c632Sopenharmony_ci public function testAnyUnpackInvalidTypeUrl() 93ffe3c632Sopenharmony_ci { 94ffe3c632Sopenharmony_ci $any = new Any(); 95ffe3c632Sopenharmony_ci $any->setTypeUrl("invalid"); 96ffe3c632Sopenharmony_ci $any->unpack(); 97ffe3c632Sopenharmony_ci } 98ffe3c632Sopenharmony_ci 99ffe3c632Sopenharmony_ci /** 100ffe3c632Sopenharmony_ci * @expectedException Exception 101ffe3c632Sopenharmony_ci */ 102ffe3c632Sopenharmony_ci public function testAnyUnpackMessageNotAdded() 103ffe3c632Sopenharmony_ci { 104ffe3c632Sopenharmony_ci $any = new Any(); 105ffe3c632Sopenharmony_ci $any->setTypeUrl("type.googleapis.com/MessageNotAdded"); 106ffe3c632Sopenharmony_ci $any->unpack(); 107ffe3c632Sopenharmony_ci } 108ffe3c632Sopenharmony_ci 109ffe3c632Sopenharmony_ci /** 110ffe3c632Sopenharmony_ci * @expectedException Exception 111ffe3c632Sopenharmony_ci */ 112ffe3c632Sopenharmony_ci public function testAnyUnpackDecodeError() 113ffe3c632Sopenharmony_ci { 114ffe3c632Sopenharmony_ci $any = new Any(); 115ffe3c632Sopenharmony_ci $any->setTypeUrl("type.googleapis.com/foo.TestMessage"); 116ffe3c632Sopenharmony_ci $any->setValue("abc"); 117ffe3c632Sopenharmony_ci $any->unpack(); 118ffe3c632Sopenharmony_ci } 119ffe3c632Sopenharmony_ci 120ffe3c632Sopenharmony_ci public function testApi() 121ffe3c632Sopenharmony_ci { 122ffe3c632Sopenharmony_ci $m = new Api(); 123ffe3c632Sopenharmony_ci 124ffe3c632Sopenharmony_ci $m->setName("a"); 125ffe3c632Sopenharmony_ci $this->assertSame("a", $m->getName()); 126ffe3c632Sopenharmony_ci 127ffe3c632Sopenharmony_ci $m->setMethods([new Method()]); 128ffe3c632Sopenharmony_ci $this->assertSame(1, count($m->getMethods())); 129ffe3c632Sopenharmony_ci 130ffe3c632Sopenharmony_ci $m->setOptions([new Option()]); 131ffe3c632Sopenharmony_ci $this->assertSame(1, count($m->getOptions())); 132ffe3c632Sopenharmony_ci 133ffe3c632Sopenharmony_ci $m->setVersion("a"); 134ffe3c632Sopenharmony_ci $this->assertSame("a", $m->getVersion()); 135ffe3c632Sopenharmony_ci 136ffe3c632Sopenharmony_ci $m->setSourceContext(new SourceContext()); 137ffe3c632Sopenharmony_ci $this->assertFalse(is_null($m->getSourceContext())); 138ffe3c632Sopenharmony_ci 139ffe3c632Sopenharmony_ci $m->setMixins([new Mixin()]); 140ffe3c632Sopenharmony_ci $this->assertSame(1, count($m->getMixins())); 141ffe3c632Sopenharmony_ci 142ffe3c632Sopenharmony_ci $m->setSyntax(Syntax::SYNTAX_PROTO2); 143ffe3c632Sopenharmony_ci $this->assertSame(Syntax::SYNTAX_PROTO2, $m->getSyntax()); 144ffe3c632Sopenharmony_ci 145ffe3c632Sopenharmony_ci $m = new Method(); 146ffe3c632Sopenharmony_ci 147ffe3c632Sopenharmony_ci $m->setName("a"); 148ffe3c632Sopenharmony_ci $this->assertSame("a", $m->getName()); 149ffe3c632Sopenharmony_ci 150ffe3c632Sopenharmony_ci $m->setRequestTypeUrl("a"); 151ffe3c632Sopenharmony_ci $this->assertSame("a", $m->getRequestTypeUrl()); 152ffe3c632Sopenharmony_ci 153ffe3c632Sopenharmony_ci $m->setRequestStreaming(true); 154ffe3c632Sopenharmony_ci $this->assertSame(true, $m->getRequestStreaming()); 155ffe3c632Sopenharmony_ci 156ffe3c632Sopenharmony_ci $m->setResponseTypeUrl("a"); 157ffe3c632Sopenharmony_ci $this->assertSame("a", $m->getResponseTypeUrl()); 158ffe3c632Sopenharmony_ci 159ffe3c632Sopenharmony_ci $m->setResponseStreaming(true); 160ffe3c632Sopenharmony_ci $this->assertSame(true, $m->getResponseStreaming()); 161ffe3c632Sopenharmony_ci 162ffe3c632Sopenharmony_ci $m->setOptions([new Option()]); 163ffe3c632Sopenharmony_ci $this->assertSame(1, count($m->getOptions())); 164ffe3c632Sopenharmony_ci 165ffe3c632Sopenharmony_ci $m = new Mixin(); 166ffe3c632Sopenharmony_ci 167ffe3c632Sopenharmony_ci $m->setName("a"); 168ffe3c632Sopenharmony_ci $this->assertSame("a", $m->getName()); 169ffe3c632Sopenharmony_ci 170ffe3c632Sopenharmony_ci $m->setRoot("a"); 171ffe3c632Sopenharmony_ci $this->assertSame("a", $m->getRoot()); 172ffe3c632Sopenharmony_ci } 173ffe3c632Sopenharmony_ci 174ffe3c632Sopenharmony_ci public function testEnum() 175ffe3c632Sopenharmony_ci { 176ffe3c632Sopenharmony_ci $m = new Enum(); 177ffe3c632Sopenharmony_ci 178ffe3c632Sopenharmony_ci $m->setName("a"); 179ffe3c632Sopenharmony_ci $this->assertSame("a", $m->getName()); 180ffe3c632Sopenharmony_ci 181ffe3c632Sopenharmony_ci $m->setEnumvalue([new EnumValue()]); 182ffe3c632Sopenharmony_ci $this->assertSame(1, count($m->getEnumvalue())); 183ffe3c632Sopenharmony_ci 184ffe3c632Sopenharmony_ci $m->setOptions([new Option()]); 185ffe3c632Sopenharmony_ci $this->assertSame(1, count($m->getOptions())); 186ffe3c632Sopenharmony_ci 187ffe3c632Sopenharmony_ci $m->setSourceContext(new SourceContext()); 188ffe3c632Sopenharmony_ci $this->assertFalse(is_null($m->getSourceContext())); 189ffe3c632Sopenharmony_ci 190ffe3c632Sopenharmony_ci $m->setSyntax(Syntax::SYNTAX_PROTO2); 191ffe3c632Sopenharmony_ci $this->assertSame(Syntax::SYNTAX_PROTO2, $m->getSyntax()); 192ffe3c632Sopenharmony_ci } 193ffe3c632Sopenharmony_ci 194ffe3c632Sopenharmony_ci public function testEnumValue() 195ffe3c632Sopenharmony_ci { 196ffe3c632Sopenharmony_ci $m = new EnumValue(); 197ffe3c632Sopenharmony_ci 198ffe3c632Sopenharmony_ci $m->setName("a"); 199ffe3c632Sopenharmony_ci $this->assertSame("a", $m->getName()); 200ffe3c632Sopenharmony_ci 201ffe3c632Sopenharmony_ci $m->setNumber(1); 202ffe3c632Sopenharmony_ci $this->assertSame(1, $m->getNumber()); 203ffe3c632Sopenharmony_ci 204ffe3c632Sopenharmony_ci $m->setOptions([new Option()]); 205ffe3c632Sopenharmony_ci $this->assertSame(1, count($m->getOptions())); 206ffe3c632Sopenharmony_ci } 207ffe3c632Sopenharmony_ci 208ffe3c632Sopenharmony_ci public function testField() 209ffe3c632Sopenharmony_ci { 210ffe3c632Sopenharmony_ci $m = new Field(); 211ffe3c632Sopenharmony_ci 212ffe3c632Sopenharmony_ci $m->setKind(Kind::TYPE_DOUBLE); 213ffe3c632Sopenharmony_ci $this->assertSame(Kind::TYPE_DOUBLE, $m->getKind()); 214ffe3c632Sopenharmony_ci 215ffe3c632Sopenharmony_ci $m->setCardinality(Cardinality::CARDINALITY_OPTIONAL); 216ffe3c632Sopenharmony_ci $this->assertSame(Cardinality::CARDINALITY_OPTIONAL, $m->getCardinality()); 217ffe3c632Sopenharmony_ci 218ffe3c632Sopenharmony_ci $m->setNumber(1); 219ffe3c632Sopenharmony_ci $this->assertSame(1, $m->getNumber()); 220ffe3c632Sopenharmony_ci 221ffe3c632Sopenharmony_ci $m->setName("a"); 222ffe3c632Sopenharmony_ci $this->assertSame("a", $m->getName()); 223ffe3c632Sopenharmony_ci 224ffe3c632Sopenharmony_ci $m->setTypeUrl("a"); 225ffe3c632Sopenharmony_ci $this->assertSame("a", $m->getTypeUrl()); 226ffe3c632Sopenharmony_ci 227ffe3c632Sopenharmony_ci $m->setOneofIndex(1); 228ffe3c632Sopenharmony_ci $this->assertSame(1, $m->getOneofIndex()); 229ffe3c632Sopenharmony_ci 230ffe3c632Sopenharmony_ci $m->setPacked(true); 231ffe3c632Sopenharmony_ci $this->assertSame(true, $m->getPacked()); 232ffe3c632Sopenharmony_ci 233ffe3c632Sopenharmony_ci $m->setOptions([new Option()]); 234ffe3c632Sopenharmony_ci $this->assertSame(1, count($m->getOptions())); 235ffe3c632Sopenharmony_ci 236ffe3c632Sopenharmony_ci $m->setJsonName("a"); 237ffe3c632Sopenharmony_ci $this->assertSame("a", $m->getJsonName()); 238ffe3c632Sopenharmony_ci 239ffe3c632Sopenharmony_ci $m->setDefaultValue("a"); 240ffe3c632Sopenharmony_ci $this->assertSame("a", $m->getDefaultValue()); 241ffe3c632Sopenharmony_ci } 242ffe3c632Sopenharmony_ci 243ffe3c632Sopenharmony_ci public function testFieldMask() 244ffe3c632Sopenharmony_ci { 245ffe3c632Sopenharmony_ci $m = new FieldMask(); 246ffe3c632Sopenharmony_ci $m->setPaths(["a"]); 247ffe3c632Sopenharmony_ci $this->assertSame(1, count($m->getPaths())); 248ffe3c632Sopenharmony_ci } 249ffe3c632Sopenharmony_ci 250ffe3c632Sopenharmony_ci public function testOption() 251ffe3c632Sopenharmony_ci { 252ffe3c632Sopenharmony_ci $m = new Option(); 253ffe3c632Sopenharmony_ci 254ffe3c632Sopenharmony_ci $m->setName("a"); 255ffe3c632Sopenharmony_ci $this->assertSame("a", $m->getName()); 256ffe3c632Sopenharmony_ci 257ffe3c632Sopenharmony_ci $m->setValue(new Any()); 258ffe3c632Sopenharmony_ci $this->assertFalse(is_null($m->getValue())); 259ffe3c632Sopenharmony_ci } 260ffe3c632Sopenharmony_ci 261ffe3c632Sopenharmony_ci public function testSourceContext() 262ffe3c632Sopenharmony_ci { 263ffe3c632Sopenharmony_ci $m = new SourceContext(); 264ffe3c632Sopenharmony_ci $m->setFileName("a"); 265ffe3c632Sopenharmony_ci $this->assertSame("a", $m->getFileName()); 266ffe3c632Sopenharmony_ci } 267ffe3c632Sopenharmony_ci 268ffe3c632Sopenharmony_ci public function testStruct() 269ffe3c632Sopenharmony_ci { 270ffe3c632Sopenharmony_ci $m = new ListValue(); 271ffe3c632Sopenharmony_ci $m->setValues([new Value()]); 272ffe3c632Sopenharmony_ci $this->assertSame(1, count($m->getValues())); 273ffe3c632Sopenharmony_ci 274ffe3c632Sopenharmony_ci $m = new Value(); 275ffe3c632Sopenharmony_ci 276ffe3c632Sopenharmony_ci $m->setNullValue(NullValue::NULL_VALUE); 277ffe3c632Sopenharmony_ci $this->assertSame(NullValue::NULL_VALUE, $m->getNullValue()); 278ffe3c632Sopenharmony_ci $this->assertSame("null_value", $m->getKind()); 279ffe3c632Sopenharmony_ci 280ffe3c632Sopenharmony_ci $m->setNumberValue(1.0); 281ffe3c632Sopenharmony_ci $this->assertSame(1.0, $m->getNumberValue()); 282ffe3c632Sopenharmony_ci $this->assertSame("number_value", $m->getKind()); 283ffe3c632Sopenharmony_ci 284ffe3c632Sopenharmony_ci $m->setStringValue("a"); 285ffe3c632Sopenharmony_ci $this->assertSame("a", $m->getStringValue()); 286ffe3c632Sopenharmony_ci $this->assertSame("string_value", $m->getKind()); 287ffe3c632Sopenharmony_ci 288ffe3c632Sopenharmony_ci $m->setBoolValue(true); 289ffe3c632Sopenharmony_ci $this->assertSame(true, $m->getBoolValue()); 290ffe3c632Sopenharmony_ci $this->assertSame("bool_value", $m->getKind()); 291ffe3c632Sopenharmony_ci 292ffe3c632Sopenharmony_ci $m->setStructValue(new Struct()); 293ffe3c632Sopenharmony_ci $this->assertFalse(is_null($m->getStructValue())); 294ffe3c632Sopenharmony_ci $this->assertSame("struct_value", $m->getKind()); 295ffe3c632Sopenharmony_ci 296ffe3c632Sopenharmony_ci $m->setListValue(new ListValue()); 297ffe3c632Sopenharmony_ci $this->assertFalse(is_null($m->getListValue())); 298ffe3c632Sopenharmony_ci $this->assertSame("list_value", $m->getKind()); 299ffe3c632Sopenharmony_ci 300ffe3c632Sopenharmony_ci $m = new Struct(); 301ffe3c632Sopenharmony_ci $m->setFields(array("a"=>new Value())); 302ffe3c632Sopenharmony_ci $this->assertSame(1, count($m->getFields())); 303ffe3c632Sopenharmony_ci } 304ffe3c632Sopenharmony_ci 305ffe3c632Sopenharmony_ci public function testTimestamp() 306ffe3c632Sopenharmony_ci { 307ffe3c632Sopenharmony_ci $timestamp = new Timestamp(); 308ffe3c632Sopenharmony_ci 309ffe3c632Sopenharmony_ci $timestamp->setSeconds(1); 310ffe3c632Sopenharmony_ci $timestamp->setNanos(2); 311ffe3c632Sopenharmony_ci $this->assertEquals(1, $timestamp->getSeconds()); 312ffe3c632Sopenharmony_ci $this->assertSame(2, $timestamp->getNanos()); 313ffe3c632Sopenharmony_ci 314ffe3c632Sopenharmony_ci date_default_timezone_set('UTC'); 315ffe3c632Sopenharmony_ci $from = new DateTime('2011-01-01T15:03:01.012345UTC'); 316ffe3c632Sopenharmony_ci $timestamp->fromDateTime($from); 317ffe3c632Sopenharmony_ci $this->assertEquals($from->format('U'), $timestamp->getSeconds()); 318ffe3c632Sopenharmony_ci $this->assertEquals(1000 * $from->format('u'), $timestamp->getNanos()); 319ffe3c632Sopenharmony_ci 320ffe3c632Sopenharmony_ci $to = $timestamp->toDateTime(); 321ffe3c632Sopenharmony_ci $this->assertSame(\DateTime::class, get_class($to)); 322ffe3c632Sopenharmony_ci $this->assertSame($from->format('U'), $to->format('U')); 323ffe3c632Sopenharmony_ci $this->assertSame($from->format('u'), $to->format('u')); 324ffe3c632Sopenharmony_ci } 325ffe3c632Sopenharmony_ci 326ffe3c632Sopenharmony_ci public function testType() 327ffe3c632Sopenharmony_ci { 328ffe3c632Sopenharmony_ci $m = new Type(); 329ffe3c632Sopenharmony_ci 330ffe3c632Sopenharmony_ci $m->setName("a"); 331ffe3c632Sopenharmony_ci $this->assertSame("a", $m->getName()); 332ffe3c632Sopenharmony_ci 333ffe3c632Sopenharmony_ci $m->setFields([new Field()]); 334ffe3c632Sopenharmony_ci $this->assertSame(1, count($m->getFields())); 335ffe3c632Sopenharmony_ci 336ffe3c632Sopenharmony_ci $m->setOneofs(["a"]); 337ffe3c632Sopenharmony_ci $this->assertSame(1, count($m->getOneofs())); 338ffe3c632Sopenharmony_ci 339ffe3c632Sopenharmony_ci $m->setOptions([new Option()]); 340ffe3c632Sopenharmony_ci $this->assertSame(1, count($m->getOptions())); 341ffe3c632Sopenharmony_ci 342ffe3c632Sopenharmony_ci $m->setSourceContext(new SourceContext()); 343ffe3c632Sopenharmony_ci $this->assertFalse(is_null($m->getSourceContext())); 344ffe3c632Sopenharmony_ci 345ffe3c632Sopenharmony_ci $m->setSyntax(Syntax::SYNTAX_PROTO2); 346ffe3c632Sopenharmony_ci $this->assertSame(Syntax::SYNTAX_PROTO2, $m->getSyntax()); 347ffe3c632Sopenharmony_ci } 348ffe3c632Sopenharmony_ci 349ffe3c632Sopenharmony_ci public function testDuration() 350ffe3c632Sopenharmony_ci { 351ffe3c632Sopenharmony_ci $duration = new Duration(); 352ffe3c632Sopenharmony_ci 353ffe3c632Sopenharmony_ci $duration->setSeconds(1); 354ffe3c632Sopenharmony_ci $duration->setNanos(2); 355ffe3c632Sopenharmony_ci $this->assertEquals(1, $duration->getSeconds()); 356ffe3c632Sopenharmony_ci $this->assertSame(2, $duration->getNanos()); 357ffe3c632Sopenharmony_ci } 358ffe3c632Sopenharmony_ci 359ffe3c632Sopenharmony_ci public function testWrappers() 360ffe3c632Sopenharmony_ci { 361ffe3c632Sopenharmony_ci $m = new DoubleValue(); 362ffe3c632Sopenharmony_ci $m->setValue(1.0); 363ffe3c632Sopenharmony_ci $this->assertSame(1.0, $m->getValue()); 364ffe3c632Sopenharmony_ci 365ffe3c632Sopenharmony_ci $m = new FloatValue(); 366ffe3c632Sopenharmony_ci $m->setValue(1.0); 367ffe3c632Sopenharmony_ci $this->assertSame(1.0, $m->getValue()); 368ffe3c632Sopenharmony_ci 369ffe3c632Sopenharmony_ci $m = new Int64Value(); 370ffe3c632Sopenharmony_ci $m->setValue(1); 371ffe3c632Sopenharmony_ci $this->assertEquals(1, $m->getValue()); 372ffe3c632Sopenharmony_ci 373ffe3c632Sopenharmony_ci $m = new UInt64Value(); 374ffe3c632Sopenharmony_ci $m->setValue(1); 375ffe3c632Sopenharmony_ci $this->assertEquals(1, $m->getValue()); 376ffe3c632Sopenharmony_ci 377ffe3c632Sopenharmony_ci $m = new Int32Value(); 378ffe3c632Sopenharmony_ci $m->setValue(1); 379ffe3c632Sopenharmony_ci $this->assertSame(1, $m->getValue()); 380ffe3c632Sopenharmony_ci 381ffe3c632Sopenharmony_ci $m = new UInt32Value(); 382ffe3c632Sopenharmony_ci $m->setValue(1); 383ffe3c632Sopenharmony_ci $this->assertSame(1, $m->getValue()); 384ffe3c632Sopenharmony_ci 385ffe3c632Sopenharmony_ci $m = new BoolValue(); 386ffe3c632Sopenharmony_ci $m->setValue(true); 387ffe3c632Sopenharmony_ci $this->assertSame(true, $m->getValue()); 388ffe3c632Sopenharmony_ci 389ffe3c632Sopenharmony_ci $m = new StringValue(); 390ffe3c632Sopenharmony_ci $m->setValue("a"); 391ffe3c632Sopenharmony_ci $this->assertSame("a", $m->getValue()); 392ffe3c632Sopenharmony_ci 393ffe3c632Sopenharmony_ci $m = new BytesValue(); 394ffe3c632Sopenharmony_ci $m->setValue("a"); 395ffe3c632Sopenharmony_ci $this->assertSame("a", $m->getValue()); 396ffe3c632Sopenharmony_ci } 397ffe3c632Sopenharmony_ci 398ffe3c632Sopenharmony_ci /** 399ffe3c632Sopenharmony_ci * @dataProvider enumNameValueConversionDataProvider 400ffe3c632Sopenharmony_ci */ 401ffe3c632Sopenharmony_ci public function testEnumNameValueConversion($class) 402ffe3c632Sopenharmony_ci { 403ffe3c632Sopenharmony_ci $reflectionClass = new ReflectionClass($class); 404ffe3c632Sopenharmony_ci $constants = $reflectionClass->getConstants(); 405ffe3c632Sopenharmony_ci foreach ($constants as $k => $v) { 406ffe3c632Sopenharmony_ci $this->assertSame($k, $class::name($v)); 407ffe3c632Sopenharmony_ci $this->assertSame($v, $class::value($k)); 408ffe3c632Sopenharmony_ci } 409ffe3c632Sopenharmony_ci } 410ffe3c632Sopenharmony_ci 411ffe3c632Sopenharmony_ci public function enumNameValueConversionDataProvider() 412ffe3c632Sopenharmony_ci { 413ffe3c632Sopenharmony_ci return [ 414ffe3c632Sopenharmony_ci ['\Google\Protobuf\Field\Cardinality'], 415ffe3c632Sopenharmony_ci ['\Google\Protobuf\Field\Kind'], 416ffe3c632Sopenharmony_ci ['\Google\Protobuf\NullValue'], 417ffe3c632Sopenharmony_ci ['\Google\Protobuf\Syntax'], 418ffe3c632Sopenharmony_ci ]; 419ffe3c632Sopenharmony_ci } 420ffe3c632Sopenharmony_ci} 421