Add json encode/decode for php. (#3226)
* Add json encode/decode for php. * Fix php conformance test on 32-bit machines. * Fix conformance test for c extension. * Fix commentspull/3301/head
parent
5a52b3588d
commit
ecca6ea95d
36 changed files with 3118 additions and 2274 deletions
@ -0,0 +1,21 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
define("GOOGLE_INTERNAL_NAMESPACE", "Google\\Protobuf\\Internal\\"); |
||||||
|
define("GOOGLE_NAMESPACE", "Google\\Protobuf\\"); |
||||||
|
define("GOOGLE_GPBMETADATA_NAMESPACE", "GPBMetadata\\Google\\Protobuf\\Internal\\"); |
||||||
|
|
||||||
|
function protobuf_autoloader_impl($class, $prefix) { |
||||||
|
$length = strlen($prefix); |
||||||
|
if ((substr($class, 0, $length) === $prefix)) { |
||||||
|
$path = '../php/src/' . implode('/', array_map('ucwords', explode('\\', $class))) . '.php'; |
||||||
|
include_once $path; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
function protobuf_autoloader($class) { |
||||||
|
protobuf_autoloader_impl($class, GOOGLE_INTERNAL_NAMESPACE); |
||||||
|
protobuf_autoloader_impl($class, GOOGLE_NAMESPACE); |
||||||
|
protobuf_autoloader_impl($class, GOOGLE_GPBMETADATA_NAMESPACE); |
||||||
|
} |
||||||
|
|
||||||
|
spl_autoload_register('protobuf_autoloader'); |
@ -0,0 +1,225 @@ |
|||||||
|
Recommended.FieldMaskNumbersDontRoundTrip.JsonOutput |
||||||
|
Recommended.FieldMaskPathsDontRoundTrip.JsonOutput |
||||||
|
Recommended.FieldMaskTooManyUnderscore.JsonOutput |
||||||
|
Recommended.JsonInput.BoolFieldIntegerOne |
||||||
|
Recommended.JsonInput.BoolFieldIntegerZero |
||||||
|
Recommended.JsonInput.DurationHas3FractionalDigits.Validator |
||||||
|
Recommended.JsonInput.DurationHas6FractionalDigits.Validator |
||||||
|
Recommended.JsonInput.DurationHas9FractionalDigits.Validator |
||||||
|
Recommended.JsonInput.DurationHasZeroFractionalDigit.Validator |
||||||
|
Recommended.JsonInput.Int64FieldBeString.Validator |
||||||
|
Recommended.JsonInput.OneofZeroBytes.JsonOutput |
||||||
|
Recommended.JsonInput.OneofZeroBytes.ProtobufOutput |
||||||
|
Recommended.JsonInput.OneofZeroDouble.JsonOutput |
||||||
|
Recommended.JsonInput.OneofZeroDouble.ProtobufOutput |
||||||
|
Recommended.JsonInput.OneofZeroFloat.JsonOutput |
||||||
|
Recommended.JsonInput.OneofZeroFloat.ProtobufOutput |
||||||
|
Recommended.JsonInput.OneofZeroString.JsonOutput |
||||||
|
Recommended.JsonInput.OneofZeroString.ProtobufOutput |
||||||
|
Recommended.JsonInput.OneofZeroUint32.JsonOutput |
||||||
|
Recommended.JsonInput.OneofZeroUint32.ProtobufOutput |
||||||
|
Recommended.JsonInput.OneofZeroUint64.JsonOutput |
||||||
|
Recommended.JsonInput.OneofZeroUint64.ProtobufOutput |
||||||
|
Recommended.JsonInput.StringEndsWithEscapeChar |
||||||
|
Recommended.JsonInput.StringFieldSurrogateInWrongOrder |
||||||
|
Recommended.JsonInput.StringFieldUnpairedHighSurrogate |
||||||
|
Recommended.JsonInput.StringFieldUnpairedLowSurrogate |
||||||
|
Recommended.JsonInput.TimestampHas3FractionalDigits.Validator |
||||||
|
Recommended.JsonInput.TimestampHas6FractionalDigits.Validator |
||||||
|
Recommended.JsonInput.TimestampHas9FractionalDigits.Validator |
||||||
|
Recommended.JsonInput.TimestampHasZeroFractionalDigit.Validator |
||||||
|
Recommended.JsonInput.TimestampZeroNormalized.Validator |
||||||
|
Recommended.JsonInput.Uint64FieldBeString.Validator |
||||||
|
Recommended.ProtobufInput.OneofZeroBytes.JsonOutput |
||||||
|
Recommended.ProtobufInput.OneofZeroBytes.ProtobufOutput |
||||||
|
Recommended.ProtobufInput.OneofZeroString.JsonOutput |
||||||
|
Recommended.ProtobufInput.OneofZeroString.ProtobufOutput |
||||||
|
Required.DurationProtoInputTooLarge.JsonOutput |
||||||
|
Required.DurationProtoInputTooSmall.JsonOutput |
||||||
|
Required.JsonInput.AllFieldAcceptNull.ProtobufOutput |
||||||
|
Required.JsonInput.Any.JsonOutput |
||||||
|
Required.JsonInput.Any.ProtobufOutput |
||||||
|
Required.JsonInput.AnyNested.JsonOutput |
||||||
|
Required.JsonInput.AnyNested.ProtobufOutput |
||||||
|
Required.JsonInput.AnyUnorderedTypeTag.JsonOutput |
||||||
|
Required.JsonInput.AnyUnorderedTypeTag.ProtobufOutput |
||||||
|
Required.JsonInput.AnyWithDuration.JsonOutput |
||||||
|
Required.JsonInput.AnyWithDuration.ProtobufOutput |
||||||
|
Required.JsonInput.AnyWithFieldMask.JsonOutput |
||||||
|
Required.JsonInput.AnyWithFieldMask.ProtobufOutput |
||||||
|
Required.JsonInput.AnyWithInt32ValueWrapper.JsonOutput |
||||||
|
Required.JsonInput.AnyWithInt32ValueWrapper.ProtobufOutput |
||||||
|
Required.JsonInput.AnyWithStruct.JsonOutput |
||||||
|
Required.JsonInput.AnyWithStruct.ProtobufOutput |
||||||
|
Required.JsonInput.AnyWithTimestamp.JsonOutput |
||||||
|
Required.JsonInput.AnyWithTimestamp.ProtobufOutput |
||||||
|
Required.JsonInput.AnyWithValueForInteger.JsonOutput |
||||||
|
Required.JsonInput.AnyWithValueForInteger.ProtobufOutput |
||||||
|
Required.JsonInput.AnyWithValueForJsonObject.JsonOutput |
||||||
|
Required.JsonInput.AnyWithValueForJsonObject.ProtobufOutput |
||||||
|
Required.JsonInput.BoolFieldFalse.ProtobufOutput |
||||||
|
Required.JsonInput.BoolMapField.JsonOutput |
||||||
|
Required.JsonInput.DoubleFieldInfinity.JsonOutput |
||||||
|
Required.JsonInput.DoubleFieldInfinity.ProtobufOutput |
||||||
|
Required.JsonInput.DoubleFieldMaxNegativeValue.JsonOutput |
||||||
|
Required.JsonInput.DoubleFieldMaxNegativeValue.ProtobufOutput |
||||||
|
Required.JsonInput.DoubleFieldMaxPositiveValue.JsonOutput |
||||||
|
Required.JsonInput.DoubleFieldMaxPositiveValue.ProtobufOutput |
||||||
|
Required.JsonInput.DoubleFieldMinNegativeValue.JsonOutput |
||||||
|
Required.JsonInput.DoubleFieldMinNegativeValue.ProtobufOutput |
||||||
|
Required.JsonInput.DoubleFieldMinPositiveValue.JsonOutput |
||||||
|
Required.JsonInput.DoubleFieldMinPositiveValue.ProtobufOutput |
||||||
|
Required.JsonInput.DoubleFieldNan.JsonOutput |
||||||
|
Required.JsonInput.DoubleFieldNan.ProtobufOutput |
||||||
|
Required.JsonInput.DoubleFieldNegativeInfinity.JsonOutput |
||||||
|
Required.JsonInput.DoubleFieldNegativeInfinity.ProtobufOutput |
||||||
|
Required.JsonInput.DoubleFieldQuotedValue.JsonOutput |
||||||
|
Required.JsonInput.DoubleFieldQuotedValue.ProtobufOutput |
||||||
|
Required.JsonInput.DurationMaxValue.JsonOutput |
||||||
|
Required.JsonInput.DurationMaxValue.ProtobufOutput |
||||||
|
Required.JsonInput.DurationMinValue.JsonOutput |
||||||
|
Required.JsonInput.DurationMinValue.ProtobufOutput |
||||||
|
Required.JsonInput.DurationRepeatedValue.JsonOutput |
||||||
|
Required.JsonInput.DurationRepeatedValue.ProtobufOutput |
||||||
|
Required.JsonInput.EnumField.ProtobufOutput |
||||||
|
Required.JsonInput.EnumFieldNumericValueNonZero.JsonOutput |
||||||
|
Required.JsonInput.EnumFieldNumericValueNonZero.ProtobufOutput |
||||||
|
Required.JsonInput.EnumFieldNumericValueZero.JsonOutput |
||||||
|
Required.JsonInput.EnumFieldNumericValueZero.ProtobufOutput |
||||||
|
Required.JsonInput.EnumFieldUnknownValue.Validator |
||||||
|
Required.JsonInput.FieldMask.JsonOutput |
||||||
|
Required.JsonInput.FieldMask.ProtobufOutput |
||||||
|
Required.JsonInput.FloatFieldInfinity.JsonOutput |
||||||
|
Required.JsonInput.FloatFieldInfinity.ProtobufOutput |
||||||
|
Required.JsonInput.FloatFieldNan.JsonOutput |
||||||
|
Required.JsonInput.FloatFieldNan.ProtobufOutput |
||||||
|
Required.JsonInput.FloatFieldNegativeInfinity.JsonOutput |
||||||
|
Required.JsonInput.FloatFieldNegativeInfinity.ProtobufOutput |
||||||
|
Required.JsonInput.FloatFieldQuotedValue.JsonOutput |
||||||
|
Required.JsonInput.FloatFieldQuotedValue.ProtobufOutput |
||||||
|
Required.JsonInput.FloatFieldTooLarge |
||||||
|
Required.JsonInput.FloatFieldTooSmall |
||||||
|
Required.JsonInput.Int32FieldExponentialFormat.JsonOutput |
||||||
|
Required.JsonInput.Int32FieldExponentialFormat.ProtobufOutput |
||||||
|
Required.JsonInput.Int32FieldFloatTrailingZero.JsonOutput |
||||||
|
Required.JsonInput.Int32FieldFloatTrailingZero.ProtobufOutput |
||||||
|
Required.JsonInput.Int32FieldMaxFloatValue.JsonOutput |
||||||
|
Required.JsonInput.Int32FieldMaxFloatValue.ProtobufOutput |
||||||
|
Required.JsonInput.Int32FieldMinFloatValue.JsonOutput |
||||||
|
Required.JsonInput.Int32FieldMinFloatValue.ProtobufOutput |
||||||
|
Required.JsonInput.Int32FieldStringValue.JsonOutput |
||||||
|
Required.JsonInput.Int32FieldStringValue.ProtobufOutput |
||||||
|
Required.JsonInput.Int32FieldStringValueEscaped.JsonOutput |
||||||
|
Required.JsonInput.Int32FieldStringValueEscaped.ProtobufOutput |
||||||
|
Required.JsonInput.Int32MapEscapedKey.JsonOutput |
||||||
|
Required.JsonInput.Int32MapEscapedKey.ProtobufOutput |
||||||
|
Required.JsonInput.Int32MapField.JsonOutput |
||||||
|
Required.JsonInput.Int32MapField.ProtobufOutput |
||||||
|
Required.JsonInput.Int64FieldMaxValue.JsonOutput |
||||||
|
Required.JsonInput.Int64FieldMaxValue.ProtobufOutput |
||||||
|
Required.JsonInput.Int64FieldMinValue.JsonOutput |
||||||
|
Required.JsonInput.Int64FieldMinValue.ProtobufOutput |
||||||
|
Required.JsonInput.Int64MapEscapedKey.JsonOutput |
||||||
|
Required.JsonInput.Int64MapEscapedKey.ProtobufOutput |
||||||
|
Required.JsonInput.Int64MapField.JsonOutput |
||||||
|
Required.JsonInput.Int64MapField.ProtobufOutput |
||||||
|
Required.JsonInput.MessageField.JsonOutput |
||||||
|
Required.JsonInput.MessageField.ProtobufOutput |
||||||
|
Required.JsonInput.MessageMapField.JsonOutput |
||||||
|
Required.JsonInput.MessageMapField.ProtobufOutput |
||||||
|
Required.JsonInput.MessageRepeatedField.JsonOutput |
||||||
|
Required.JsonInput.MessageRepeatedField.ProtobufOutput |
||||||
|
Required.JsonInput.OptionalBoolWrapper.JsonOutput |
||||||
|
Required.JsonInput.OptionalBoolWrapper.ProtobufOutput |
||||||
|
Required.JsonInput.OptionalBytesWrapper.JsonOutput |
||||||
|
Required.JsonInput.OptionalBytesWrapper.ProtobufOutput |
||||||
|
Required.JsonInput.OptionalDoubleWrapper.JsonOutput |
||||||
|
Required.JsonInput.OptionalDoubleWrapper.ProtobufOutput |
||||||
|
Required.JsonInput.OptionalFloatWrapper.JsonOutput |
||||||
|
Required.JsonInput.OptionalFloatWrapper.ProtobufOutput |
||||||
|
Required.JsonInput.OptionalInt32Wrapper.JsonOutput |
||||||
|
Required.JsonInput.OptionalInt32Wrapper.ProtobufOutput |
||||||
|
Required.JsonInput.OptionalInt64Wrapper.JsonOutput |
||||||
|
Required.JsonInput.OptionalInt64Wrapper.ProtobufOutput |
||||||
|
Required.JsonInput.OptionalStringWrapper.JsonOutput |
||||||
|
Required.JsonInput.OptionalStringWrapper.ProtobufOutput |
||||||
|
Required.JsonInput.OptionalUint32Wrapper.JsonOutput |
||||||
|
Required.JsonInput.OptionalUint32Wrapper.ProtobufOutput |
||||||
|
Required.JsonInput.OptionalUint64Wrapper.JsonOutput |
||||||
|
Required.JsonInput.OptionalUint64Wrapper.ProtobufOutput |
||||||
|
Required.JsonInput.OptionalWrapperTypesWithNonDefaultValue.JsonOutput |
||||||
|
Required.JsonInput.OptionalWrapperTypesWithNonDefaultValue.ProtobufOutput |
||||||
|
Required.JsonInput.PrimitiveRepeatedField.JsonOutput |
||||||
|
Required.JsonInput.PrimitiveRepeatedField.ProtobufOutput |
||||||
|
Required.JsonInput.RepeatedBoolWrapper.JsonOutput |
||||||
|
Required.JsonInput.RepeatedBoolWrapper.ProtobufOutput |
||||||
|
Required.JsonInput.RepeatedBytesWrapper.JsonOutput |
||||||
|
Required.JsonInput.RepeatedBytesWrapper.ProtobufOutput |
||||||
|
Required.JsonInput.RepeatedDoubleWrapper.JsonOutput |
||||||
|
Required.JsonInput.RepeatedDoubleWrapper.ProtobufOutput |
||||||
|
Required.JsonInput.RepeatedFieldWrongElementTypeExpectingStringsGotInt |
||||||
|
Required.JsonInput.RepeatedFloatWrapper.JsonOutput |
||||||
|
Required.JsonInput.RepeatedFloatWrapper.ProtobufOutput |
||||||
|
Required.JsonInput.RepeatedInt32Wrapper.JsonOutput |
||||||
|
Required.JsonInput.RepeatedInt32Wrapper.ProtobufOutput |
||||||
|
Required.JsonInput.RepeatedInt64Wrapper.JsonOutput |
||||||
|
Required.JsonInput.RepeatedInt64Wrapper.ProtobufOutput |
||||||
|
Required.JsonInput.RepeatedStringWrapper.JsonOutput |
||||||
|
Required.JsonInput.RepeatedStringWrapper.ProtobufOutput |
||||||
|
Required.JsonInput.RepeatedUint32Wrapper.JsonOutput |
||||||
|
Required.JsonInput.RepeatedUint32Wrapper.ProtobufOutput |
||||||
|
Required.JsonInput.RepeatedUint64Wrapper.JsonOutput |
||||||
|
Required.JsonInput.RepeatedUint64Wrapper.ProtobufOutput |
||||||
|
Required.JsonInput.StringFieldEscape.JsonOutput |
||||||
|
Required.JsonInput.StringFieldEscape.ProtobufOutput |
||||||
|
Required.JsonInput.StringFieldNotAString |
||||||
|
Required.JsonInput.StringFieldSurrogatePair.JsonOutput |
||||||
|
Required.JsonInput.StringFieldSurrogatePair.ProtobufOutput |
||||||
|
Required.JsonInput.StringFieldUnicodeEscape.JsonOutput |
||||||
|
Required.JsonInput.StringFieldUnicodeEscape.ProtobufOutput |
||||||
|
Required.JsonInput.StringFieldUnicodeEscapeWithLowercaseHexLetters.JsonOutput |
||||||
|
Required.JsonInput.StringFieldUnicodeEscapeWithLowercaseHexLetters.ProtobufOutput |
||||||
|
Required.JsonInput.Struct.JsonOutput |
||||||
|
Required.JsonInput.Struct.ProtobufOutput |
||||||
|
Required.JsonInput.TimestampMaxValue.JsonOutput |
||||||
|
Required.JsonInput.TimestampMaxValue.ProtobufOutput |
||||||
|
Required.JsonInput.TimestampMinValue.JsonOutput |
||||||
|
Required.JsonInput.TimestampMinValue.ProtobufOutput |
||||||
|
Required.JsonInput.TimestampRepeatedValue.JsonOutput |
||||||
|
Required.JsonInput.TimestampRepeatedValue.ProtobufOutput |
||||||
|
Required.JsonInput.TimestampWithNegativeOffset.JsonOutput |
||||||
|
Required.JsonInput.TimestampWithNegativeOffset.ProtobufOutput |
||||||
|
Required.JsonInput.TimestampWithPositiveOffset.JsonOutput |
||||||
|
Required.JsonInput.TimestampWithPositiveOffset.ProtobufOutput |
||||||
|
Required.JsonInput.Uint32FieldMaxFloatValue.JsonOutput |
||||||
|
Required.JsonInput.Uint32FieldMaxFloatValue.ProtobufOutput |
||||||
|
Required.JsonInput.Uint32MapField.JsonOutput |
||||||
|
Required.JsonInput.Uint32MapField.ProtobufOutput |
||||||
|
Required.JsonInput.Uint64FieldMaxValue.JsonOutput |
||||||
|
Required.JsonInput.Uint64FieldMaxValue.ProtobufOutput |
||||||
|
Required.JsonInput.Uint64MapField.JsonOutput |
||||||
|
Required.JsonInput.Uint64MapField.ProtobufOutput |
||||||
|
Required.JsonInput.ValueAcceptBool.JsonOutput |
||||||
|
Required.JsonInput.ValueAcceptBool.ProtobufOutput |
||||||
|
Required.JsonInput.ValueAcceptFloat.JsonOutput |
||||||
|
Required.JsonInput.ValueAcceptFloat.ProtobufOutput |
||||||
|
Required.JsonInput.ValueAcceptInteger.JsonOutput |
||||||
|
Required.JsonInput.ValueAcceptInteger.ProtobufOutput |
||||||
|
Required.JsonInput.ValueAcceptList.JsonOutput |
||||||
|
Required.JsonInput.ValueAcceptList.ProtobufOutput |
||||||
|
Required.JsonInput.ValueAcceptNull.JsonOutput |
||||||
|
Required.JsonInput.ValueAcceptNull.ProtobufOutput |
||||||
|
Required.JsonInput.ValueAcceptObject.JsonOutput |
||||||
|
Required.JsonInput.ValueAcceptObject.ProtobufOutput |
||||||
|
Required.JsonInput.ValueAcceptString.JsonOutput |
||||||
|
Required.JsonInput.ValueAcceptString.ProtobufOutput |
||||||
|
Required.JsonInput.WrapperTypesWithNullValue.ProtobufOutput |
||||||
|
Required.ProtobufInput.DoubleFieldNormalizeQuietNan.JsonOutput |
||||||
|
Required.ProtobufInput.DoubleFieldNormalizeSignalingNan.JsonOutput |
||||||
|
Required.ProtobufInput.FloatFieldNormalizeQuietNan.JsonOutput |
||||||
|
Required.ProtobufInput.FloatFieldNormalizeSignalingNan.JsonOutput |
||||||
|
Required.ProtobufInput.RepeatedScalarSelectsLast.FIXED32.ProtobufOutput |
||||||
|
Required.ProtobufInput.RepeatedScalarSelectsLast.FIXED64.ProtobufOutput |
||||||
|
Required.ProtobufInput.RepeatedScalarSelectsLast.UINT64.ProtobufOutput |
||||||
|
Required.TimestampProtoInputTooLarge.JsonOutput |
||||||
|
Required.TimestampProtoInputTooSmall.JsonOutput |
@ -0,0 +1,285 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
// Protocol Buffers - Google's data interchange format |
||||||
|
// Copyright 2008 Google Inc. All rights reserved. |
||||||
|
// https://developers.google.com/protocol-buffers/ |
||||||
|
// |
||||||
|
// Redistribution and use in source and binary forms, with or without |
||||||
|
// modification, are permitted provided that the following conditions are |
||||||
|
// met: |
||||||
|
// |
||||||
|
// * Redistributions of source code must retain the above copyright |
||||||
|
// notice, this list of conditions and the following disclaimer. |
||||||
|
// * Redistributions in binary form must reproduce the above |
||||||
|
// copyright notice, this list of conditions and the following disclaimer |
||||||
|
// in the documentation and/or other materials provided with the |
||||||
|
// distribution. |
||||||
|
// * Neither the name of Google Inc. nor the names of its |
||||||
|
// contributors may be used to endorse or promote products derived from |
||||||
|
// this software without specific prior written permission. |
||||||
|
// |
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||||
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||||
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||||
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||||
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||||
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||||
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||||
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||||
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||||
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||||
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||||
|
|
||||||
|
namespace Google\Protobuf\Internal; |
||||||
|
|
||||||
|
class GPBJsonWire |
||||||
|
{ |
||||||
|
|
||||||
|
public static function serializeFieldToStream( |
||||||
|
$value, |
||||||
|
$field, |
||||||
|
&$output) |
||||||
|
{ |
||||||
|
$output->writeRaw("\"", 1); |
||||||
|
$field_name = GPBJsonWire::formatFieldName($field); |
||||||
|
$output->writeRaw($field_name, strlen($field_name)); |
||||||
|
$output->writeRaw("\":", 2); |
||||||
|
return static::serializeFieldValueToStream($value, $field, $output); |
||||||
|
} |
||||||
|
|
||||||
|
private static function serializeFieldValueToStream( |
||||||
|
$values, |
||||||
|
$field, |
||||||
|
&$output) |
||||||
|
{ |
||||||
|
if ($field->isMap()) { |
||||||
|
$output->writeRaw("{", 1); |
||||||
|
$first = true; |
||||||
|
$map_entry = $field->getMessageType(); |
||||||
|
$key_field = $map_entry->getFieldByNumber(1); |
||||||
|
$value_field = $map_entry->getFieldByNumber(2); |
||||||
|
|
||||||
|
switch ($key_field->getType()) { |
||||||
|
case GPBType::STRING: |
||||||
|
case GPBType::SFIXED64: |
||||||
|
case GPBType::INT64: |
||||||
|
case GPBType::SINT64: |
||||||
|
case GPBType::FIXED64: |
||||||
|
case GPBType::UINT64: |
||||||
|
$additional_quote = false; |
||||||
|
break; |
||||||
|
default: |
||||||
|
$additional_quote = true; |
||||||
|
} |
||||||
|
|
||||||
|
foreach ($values as $key => $value) { |
||||||
|
if ($first) { |
||||||
|
$first = false; |
||||||
|
} else { |
||||||
|
$output->writeRaw(",", 1); |
||||||
|
} |
||||||
|
if ($additional_quote) { |
||||||
|
$output->writeRaw("\"", 1); |
||||||
|
} |
||||||
|
if (!static::serializeSingularFieldValueToStream( |
||||||
|
$key, |
||||||
|
$key_field, |
||||||
|
$output)) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
if ($additional_quote) { |
||||||
|
$output->writeRaw("\"", 1); |
||||||
|
} |
||||||
|
$output->writeRaw(":", 1); |
||||||
|
if (!static::serializeSingularFieldValueToStream( |
||||||
|
$value, |
||||||
|
$value_field, |
||||||
|
$output)) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
$output->writeRaw("}", 1); |
||||||
|
return true; |
||||||
|
} elseif ($field->isRepeated()) { |
||||||
|
$output->writeRaw("[", 1); |
||||||
|
$first = true; |
||||||
|
foreach ($values as $value) { |
||||||
|
if ($first) { |
||||||
|
$first = false; |
||||||
|
} else { |
||||||
|
$output->writeRaw(",", 1); |
||||||
|
} |
||||||
|
if (!static::serializeSingularFieldValueToStream( |
||||||
|
$value, |
||||||
|
$field, |
||||||
|
$output)) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
$output->writeRaw("]", 1); |
||||||
|
return true; |
||||||
|
} else { |
||||||
|
return static::serializeSingularFieldValueToStream( |
||||||
|
$values, |
||||||
|
$field, |
||||||
|
$output); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private static function serializeSingularFieldValueToStream( |
||||||
|
$value, |
||||||
|
$field, |
||||||
|
&$output) |
||||||
|
{ |
||||||
|
switch ($field->getType()) { |
||||||
|
case GPBType::SFIXED32: |
||||||
|
case GPBType::SINT32: |
||||||
|
case GPBType::INT32: |
||||||
|
$str_value = strval($value); |
||||||
|
$output->writeRaw($str_value, strlen($str_value)); |
||||||
|
break; |
||||||
|
case GPBType::FIXED32: |
||||||
|
case GPBType::UINT32: |
||||||
|
if ($value < 0) { |
||||||
|
$value = bcadd($value, "4294967296"); |
||||||
|
} |
||||||
|
$str_value = strval($value); |
||||||
|
$output->writeRaw($str_value, strlen($str_value)); |
||||||
|
break; |
||||||
|
case GPBType::FIXED64: |
||||||
|
case GPBType::UINT64: |
||||||
|
if ($value < 0) { |
||||||
|
$value = bcadd($value, "18446744073709551616"); |
||||||
|
} |
||||||
|
// Intentional fall through. |
||||||
|
case GPBType::SFIXED64: |
||||||
|
case GPBType::INT64: |
||||||
|
case GPBType::SINT64: |
||||||
|
$output->writeRaw("\"", 1); |
||||||
|
$str_value = strval($value); |
||||||
|
$output->writeRaw($str_value, strlen($str_value)); |
||||||
|
$output->writeRaw("\"", 1); |
||||||
|
break; |
||||||
|
case GPBType::FLOAT: |
||||||
|
if (is_nan($value)) { |
||||||
|
$str_value = "\"NaN\""; |
||||||
|
} elseif ($value === INF) { |
||||||
|
$str_value = "\"Infinity\""; |
||||||
|
} elseif ($value === -INF) { |
||||||
|
$str_value = "\"-Infinity\""; |
||||||
|
} else { |
||||||
|
$str_value = sprintf("%.8g", $value); |
||||||
|
} |
||||||
|
$output->writeRaw($str_value, strlen($str_value)); |
||||||
|
break; |
||||||
|
case GPBType::DOUBLE: |
||||||
|
if (is_nan($value)) { |
||||||
|
$str_value = "\"NaN\""; |
||||||
|
} elseif ($value === INF) { |
||||||
|
$str_value = "\"Infinity\""; |
||||||
|
} elseif ($value === -INF) { |
||||||
|
$str_value = "\"-Infinity\""; |
||||||
|
} else { |
||||||
|
$str_value = sprintf("%.17g", $value); |
||||||
|
} |
||||||
|
$output->writeRaw($str_value, strlen($str_value)); |
||||||
|
break; |
||||||
|
case GPBType::ENUM: |
||||||
|
$enum_desc = $field->getEnumType(); |
||||||
|
$enum_value_desc = $enum_desc->getValueByNumber($value); |
||||||
|
if (!is_null($enum_value_desc)) { |
||||||
|
$str_value = $enum_value_desc->getName(); |
||||||
|
$output->writeRaw("\"", 1); |
||||||
|
$output->writeRaw($str_value, strlen($str_value)); |
||||||
|
$output->writeRaw("\"", 1); |
||||||
|
} else { |
||||||
|
$str_value = strval($value); |
||||||
|
$output->writeRaw($str_value, strlen($str_value)); |
||||||
|
} |
||||||
|
break; |
||||||
|
case GPBType::BOOL: |
||||||
|
if ($value) { |
||||||
|
$output->writeRaw("true", 4); |
||||||
|
} else { |
||||||
|
$output->writeRaw("false", 5); |
||||||
|
} |
||||||
|
break; |
||||||
|
case GPBType::BYTES: |
||||||
|
$value = base64_encode($value); |
||||||
|
case GPBType::STRING: |
||||||
|
$value = json_encode($value); |
||||||
|
$output->writeRaw($value, strlen($value)); |
||||||
|
break; |
||||||
|
// case GPBType::GROUP: |
||||||
|
// echo "GROUP\xA"; |
||||||
|
// trigger_error("Not implemented.", E_ERROR); |
||||||
|
// break; |
||||||
|
case GPBType::MESSAGE: |
||||||
|
$value->serializeToJsonStream($output); |
||||||
|
break; |
||||||
|
default: |
||||||
|
user_error("Unsupported type."); |
||||||
|
return false; |
||||||
|
} |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
private static function formatFieldName($field) |
||||||
|
{ |
||||||
|
return $field->getJsonName(); |
||||||
|
} |
||||||
|
|
||||||
|
// Used for escaping control chars in strings. |
||||||
|
private static $k_control_char_limit = 0x20; |
||||||
|
|
||||||
|
private static function jsonNiceEscape($c) |
||||||
|
{ |
||||||
|
switch ($c) { |
||||||
|
case '"': return "\\\""; |
||||||
|
case '\\': return "\\\\"; |
||||||
|
case '/': return "\\/"; |
||||||
|
case '\b': return "\\b"; |
||||||
|
case '\f': return "\\f"; |
||||||
|
case '\n': return "\\n"; |
||||||
|
case '\r': return "\\r"; |
||||||
|
case '\t': return "\\t"; |
||||||
|
default: return NULL; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private static function isJsonEscaped($c) |
||||||
|
{ |
||||||
|
// See RFC 4627. |
||||||
|
return $c < chr($k_control_char_limit) || $c === "\"" || $c === "\\"; |
||||||
|
} |
||||||
|
|
||||||
|
public static function escapedJson($value) |
||||||
|
{ |
||||||
|
$escaped_value = ""; |
||||||
|
$unescaped_run = ""; |
||||||
|
for ($i = 0; $i < strlen($value); $i++) { |
||||||
|
$c = $value[$i]; |
||||||
|
// Handle escaping. |
||||||
|
if (static::isJsonEscaped($c)) { |
||||||
|
// Use a "nice" escape, like \n, if one exists for this |
||||||
|
// character. |
||||||
|
$escape = static::jsonNiceEscape($c); |
||||||
|
if (is_null($escape)) { |
||||||
|
$escape = "\\u00" . bin2hex($c); |
||||||
|
} |
||||||
|
if ($unescaped_run !== "") { |
||||||
|
$escaped_value .= $unescaped_run; |
||||||
|
$unescaped_run = ""; |
||||||
|
} |
||||||
|
$escaped_value .= $escape; |
||||||
|
} else { |
||||||
|
if ($unescaped_run === "") { |
||||||
|
$unescaped_run .= $c; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
$escaped_value .= $unescaped_run; |
||||||
|
return $escaped_value; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,43 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
// Protocol Buffers - Google's data interchange format |
||||||
|
// Copyright 2008 Google Inc. All rights reserved. |
||||||
|
// https://developers.google.com/protocol-buffers/ |
||||||
|
// |
||||||
|
// Redistribution and use in source and binary forms, with or without |
||||||
|
// modification, are permitted provided that the following conditions are |
||||||
|
// met: |
||||||
|
// |
||||||
|
// * Redistributions of source code must retain the above copyright |
||||||
|
// notice, this list of conditions and the following disclaimer. |
||||||
|
// * Redistributions in binary form must reproduce the above |
||||||
|
// copyright notice, this list of conditions and the following disclaimer |
||||||
|
// in the documentation and/or other materials provided with the |
||||||
|
// distribution. |
||||||
|
// * Neither the name of Google Inc. nor the names of its |
||||||
|
// contributors may be used to endorse or promote products derived from |
||||||
|
// this software without specific prior written permission. |
||||||
|
// |
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||||
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||||
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||||
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||||
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||||
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||||
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||||
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||||
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||||
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||||
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||||
|
|
||||||
|
namespace Google\Protobuf\Internal; |
||||||
|
|
||||||
|
class GPBWireType |
||||||
|
{ |
||||||
|
const VARINT = 0; |
||||||
|
const FIXED64 = 1; |
||||||
|
const LENGTH_DELIMITED = 2; |
||||||
|
const START_GROUP = 3; |
||||||
|
const END_GROUP = 4; |
||||||
|
const FIXED32 = 5; |
||||||
|
} |
@ -0,0 +1,50 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
// Protocol Buffers - Google's data interchange format |
||||||
|
// Copyright 2008 Google Inc. All rights reserved. |
||||||
|
// https://developers.google.com/protocol-buffers/ |
||||||
|
// |
||||||
|
// Redistribution and use in source and binary forms, with or without |
||||||
|
// modification, are permitted provided that the following conditions are |
||||||
|
// met: |
||||||
|
// |
||||||
|
// * Redistributions of source code must retain the above copyright |
||||||
|
// notice, this list of conditions and the following disclaimer. |
||||||
|
// * Redistributions in binary form must reproduce the above |
||||||
|
// copyright notice, this list of conditions and the following disclaimer |
||||||
|
// in the documentation and/or other materials provided with the |
||||||
|
// distribution. |
||||||
|
// * Neither the name of Google Inc. nor the names of its |
||||||
|
// contributors may be used to endorse or promote products derived from |
||||||
|
// this software without specific prior written permission. |
||||||
|
// |
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||||
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||||
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||||
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||||
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||||
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||||
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||||
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||||
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||||
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||||
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||||
|
|
||||||
|
namespace Google\Protobuf\Internal; |
||||||
|
|
||||||
|
class RawInputStream |
||||||
|
{ |
||||||
|
|
||||||
|
private $buffer; |
||||||
|
|
||||||
|
public function __construct($buffer) |
||||||
|
{ |
||||||
|
$this->buffer = $buffer; |
||||||
|
} |
||||||
|
|
||||||
|
public function getData() |
||||||
|
{ |
||||||
|
return $this->buffer; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,920 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
require_once('test_util.php'); |
||||||
|
|
||||||
|
use Google\Protobuf\Internal\RepeatedField; |
||||||
|
use Google\Protobuf\Internal\GPBType; |
||||||
|
use Foo\TestMessage; |
||||||
|
use Foo\TestMessage_Sub; |
||||||
|
|
||||||
|
class UndefinedTest extends PHPUnit_Framework_TestCase |
||||||
|
{ |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testInt32AppendStringFail() |
||||||
|
{ |
||||||
|
$arr = new RepeatedField(GPBType::INT32); |
||||||
|
$arr[] = 'abc'; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testInt32SetStringFail() |
||||||
|
{ |
||||||
|
$arr = new RepeatedField(GPBType::INT32); |
||||||
|
$arr[] = 0; |
||||||
|
$arr[0] = 'abc'; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testInt32AppendMessageFail() |
||||||
|
{ |
||||||
|
$arr = new RepeatedField(GPBType::INT32); |
||||||
|
$arr[] = new TestMessage_Sub(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testInt32SetMessageFail() |
||||||
|
{ |
||||||
|
$arr = new RepeatedField(GPBType::INT32); |
||||||
|
$arr[] = 0; |
||||||
|
$arr[0] = new TestMessage_Sub(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testUint32AppendStringFail() |
||||||
|
{ |
||||||
|
$arr = new RepeatedField(GPBType::UINT32); |
||||||
|
$arr[] = 'abc'; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testUint32SetStringFail() |
||||||
|
{ |
||||||
|
$arr = new RepeatedField(GPBType::UINT32); |
||||||
|
$arr[] = 0; |
||||||
|
$arr[0] = 'abc'; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testUint32AppendMessageFail() |
||||||
|
{ |
||||||
|
$arr = new RepeatedField(GPBType::UINT32); |
||||||
|
$arr[] = new TestMessage_Sub(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testUint32SetMessageFail() |
||||||
|
{ |
||||||
|
$arr = new RepeatedField(GPBType::UINT32); |
||||||
|
$arr[] = 0; |
||||||
|
$arr[0] = new TestMessage_Sub(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testInt64AppendStringFail() |
||||||
|
{ |
||||||
|
$arr = new RepeatedField(GPBType::INT64); |
||||||
|
$arr[] = 'abc'; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testInt64SetStringFail() |
||||||
|
{ |
||||||
|
$arr = new RepeatedField(GPBType::INT64); |
||||||
|
$arr[] = 0; |
||||||
|
$arr[0] = 'abc'; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testInt64AppendMessageFail() |
||||||
|
{ |
||||||
|
$arr = new RepeatedField(GPBType::INT64); |
||||||
|
$arr[] = new TestMessage_Sub(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testInt64SetMessageFail() |
||||||
|
{ |
||||||
|
$arr = new RepeatedField(GPBType::INT64); |
||||||
|
$arr[] = 0; |
||||||
|
$arr[0] = new TestMessage_Sub(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testUint64AppendStringFail() |
||||||
|
{ |
||||||
|
$arr = new RepeatedField(GPBType::UINT64); |
||||||
|
$arr[] = 'abc'; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testUint64SetStringFail() |
||||||
|
{ |
||||||
|
$arr = new RepeatedField(GPBType::UINT64); |
||||||
|
$arr[] = 0; |
||||||
|
$arr[0] = 'abc'; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testUint64AppendMessageFail() |
||||||
|
{ |
||||||
|
$arr = new RepeatedField(GPBType::UINT64); |
||||||
|
$arr[] = new TestMessage_Sub(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testUint64SetMessageFail() |
||||||
|
{ |
||||||
|
$arr = new RepeatedField(GPBType::UINT64); |
||||||
|
$arr[] = 0; |
||||||
|
$arr[0] = new TestMessage_Sub(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testFloatAppendStringFail() |
||||||
|
{ |
||||||
|
$arr = new RepeatedField(GPBType::FLOAT); |
||||||
|
$arr[] = 'abc'; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testFloatSetStringFail() |
||||||
|
{ |
||||||
|
$arr = new RepeatedField(GPBType::FLOAT); |
||||||
|
$arr[] = 0.0; |
||||||
|
$arr[0] = 'abc'; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testFloatAppendMessageFail() |
||||||
|
{ |
||||||
|
$arr = new RepeatedField(GPBType::FLOAT); |
||||||
|
$arr[] = new TestMessage_Sub(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testFloatSetMessageFail() |
||||||
|
{ |
||||||
|
$arr = new RepeatedField(GPBType::FLOAT); |
||||||
|
$arr[] = 0.0; |
||||||
|
$arr[0] = new TestMessage_Sub(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testDoubleAppendStringFail() |
||||||
|
{ |
||||||
|
$arr = new RepeatedField(GPBType::DOUBLE); |
||||||
|
$arr[] = 'abc'; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testDoubleSetStringFail() |
||||||
|
{ |
||||||
|
$arr = new RepeatedField(GPBType::DOUBLE); |
||||||
|
$arr[] = 0.0; |
||||||
|
$arr[0] = 'abc'; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testDoubleAppendMessageFail() |
||||||
|
{ |
||||||
|
$arr = new RepeatedField(GPBType::DOUBLE); |
||||||
|
$arr[] = new TestMessage_Sub(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testDoubleSetMessageFail() |
||||||
|
{ |
||||||
|
$arr = new RepeatedField(GPBType::DOUBLE); |
||||||
|
$arr[] = 0.0; |
||||||
|
$arr[0] = new TestMessage_Sub(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testBoolAppendMessageFail() |
||||||
|
{ |
||||||
|
$arr = new RepeatedField(GPBType::BOOL); |
||||||
|
$arr[] = new TestMessage_Sub(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testBoolSetMessageFail() |
||||||
|
{ |
||||||
|
$arr = new RepeatedField(GPBType::BOOL); |
||||||
|
$arr[] = true; |
||||||
|
$arr[0] = new TestMessage_Sub(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testStringAppendMessageFail() |
||||||
|
{ |
||||||
|
$arr = new RepeatedField(GPBType::STRING); |
||||||
|
$arr[] = new TestMessage_Sub(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testStringSetMessageFail() |
||||||
|
{ |
||||||
|
$arr = new RepeatedField(GPBType::STRING); |
||||||
|
$arr[] = 'abc'; |
||||||
|
$arr[0] = new TestMessage_Sub(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testStringAppendInvalidUTF8Fail() |
||||||
|
{ |
||||||
|
$arr = new RepeatedField(GPBType::STRING); |
||||||
|
$hex = hex2bin("ff"); |
||||||
|
$arr[] = $hex; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testStringSetInvalidUTF8Fail() |
||||||
|
{ |
||||||
|
$arr = new RepeatedField(GPBType::STRING); |
||||||
|
$arr[] = 'abc'; |
||||||
|
$hex = hex2bin("ff"); |
||||||
|
$arr[0] = $hex; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testMessageAppendIntFail() |
||||||
|
{ |
||||||
|
$arr = new RepeatedField(GPBType::MESSAGE, TestMessage_Sub::class); |
||||||
|
$arr[] = 1; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testMessageSetIntFail() |
||||||
|
{ |
||||||
|
$arr = new RepeatedField(GPBType::MESSAGE, TestMessage_Sub::class); |
||||||
|
$arr[] = new TestMessage_Sub; |
||||||
|
$arr[0] = 'abc'; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testMessageAppendStringFail() |
||||||
|
{ |
||||||
|
$arr = new RepeatedField(GPBType::MESSAGE, TestMessage_Sub::class); |
||||||
|
$arr[] = 'abc'; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testMessageSetStringFail() |
||||||
|
{ |
||||||
|
$arr = new RepeatedField(GPBType::MESSAGE, TestMessage_Sub::class); |
||||||
|
$arr[] = new TestMessage_Sub; |
||||||
|
$arr[0] = 'abc'; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testMessageAppendOtherMessageFail() |
||||||
|
{ |
||||||
|
$arr = new RepeatedField(GPBType::MESSAGE, TestMessage_Sub::class); |
||||||
|
$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; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testRemoveMiddleFail() |
||||||
|
{ |
||||||
|
$arr = new RepeatedField(GPBType::INT32); |
||||||
|
|
||||||
|
$arr[] = 0; |
||||||
|
$arr[] = 1; |
||||||
|
$arr[] = 2; |
||||||
|
$this->assertSame(3, count($arr)); |
||||||
|
|
||||||
|
unset($arr[1]); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testRemoveEmptyFail() |
||||||
|
{ |
||||||
|
$arr = new RepeatedField(GPBType::INT32); |
||||||
|
|
||||||
|
unset($arr[0]); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testMessageOffsetFail() |
||||||
|
{ |
||||||
|
$arr = new RepeatedField(GPBType::INT32); |
||||||
|
$arr[] = 0; |
||||||
|
$arr[new TestMessage_Sub()] = 0; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testStringOffsetFail() |
||||||
|
{ |
||||||
|
$arr = new RepeatedField(GPBType::INT32); |
||||||
|
$arr[] = 0; |
||||||
|
$arr['abc'] = 0; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testSetNonExistedOffsetFail() |
||||||
|
{ |
||||||
|
$arr = new RepeatedField(GPBType::INT32); |
||||||
|
$arr[0] = 0; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testInt32FieldInvalidTypeFail() |
||||||
|
{ |
||||||
|
$m = new TestMessage(); |
||||||
|
$m->setOptionalInt32(new TestMessage()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testInt32FieldInvalidStringFail() |
||||||
|
{ |
||||||
|
$m = new TestMessage(); |
||||||
|
$m->setOptionalInt32('abc'); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testUint32FieldInvalidTypeFail() |
||||||
|
{ |
||||||
|
$m = new TestMessage(); |
||||||
|
$m->setOptionalUint32(new TestMessage()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testUint32FieldInvalidStringFail() |
||||||
|
{ |
||||||
|
$m = new TestMessage(); |
||||||
|
$m->setOptionalUint32('abc'); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testInt64FieldInvalidTypeFail() |
||||||
|
{ |
||||||
|
$m = new TestMessage(); |
||||||
|
$m->setOptionalInt64(new TestMessage()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testInt64FieldInvalidStringFail() |
||||||
|
{ |
||||||
|
$m = new TestMessage(); |
||||||
|
$m->setOptionalInt64('abc'); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testUint64FieldInvalidTypeFail() |
||||||
|
{ |
||||||
|
$m = new TestMessage(); |
||||||
|
$m->setOptionalUint64(new TestMessage()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testUint64FieldInvalidStringFail() |
||||||
|
{ |
||||||
|
$m = new TestMessage(); |
||||||
|
$m->setOptionalUint64('abc'); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testFloatFieldInvalidTypeFail() |
||||||
|
{ |
||||||
|
$m = new TestMessage(); |
||||||
|
$m->setOptionalFloat(new TestMessage()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testFloatFieldInvalidStringFail() |
||||||
|
{ |
||||||
|
$m = new TestMessage(); |
||||||
|
$m->setOptionalFloat('abc'); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testDoubleFieldInvalidTypeFail() |
||||||
|
{ |
||||||
|
$m = new TestMessage(); |
||||||
|
$m->setOptionalDouble(new TestMessage()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testDoubleFieldInvalidStringFail() |
||||||
|
{ |
||||||
|
$m = new TestMessage(); |
||||||
|
$m->setOptionalDouble('abc'); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testBoolFieldInvalidStringFail() |
||||||
|
{ |
||||||
|
$m = new TestMessage(); |
||||||
|
$m->setOptionalBool(new TestMessage()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testStringFieldInvalidUTF8Fail() |
||||||
|
{ |
||||||
|
$m = new TestMessage(); |
||||||
|
$hex = hex2bin("ff"); |
||||||
|
$m->setOptionalString($hex); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testMessageFieldWrongTypeFail() |
||||||
|
{ |
||||||
|
$m = new TestMessage(); |
||||||
|
$a = 1; |
||||||
|
$m->setOptionalMessage($a); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testMessageFieldWrongClassFail() |
||||||
|
{ |
||||||
|
$m = new TestMessage(); |
||||||
|
$m->setOptionalMessage(new TestMessage()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testRepeatedFieldWrongTypeFail() |
||||||
|
{ |
||||||
|
$m = new TestMessage(); |
||||||
|
$a = 1; |
||||||
|
$m->setRepeatedInt32($a); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testRepeatedFieldWrongObjectFail() |
||||||
|
{ |
||||||
|
$m = new TestMessage(); |
||||||
|
$m->setRepeatedInt32($m); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testRepeatedFieldWrongRepeatedTypeFail() |
||||||
|
{ |
||||||
|
$m = new TestMessage(); |
||||||
|
|
||||||
|
$repeated_int32 = new RepeatedField(GPBType::UINT32); |
||||||
|
$m->setRepeatedInt32($repeated_int32); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testRepeatedFieldWrongRepeatedMessageClassFail() |
||||||
|
{ |
||||||
|
$m = new TestMessage(); |
||||||
|
|
||||||
|
$repeated_message = new RepeatedField(GPBType::MESSAGE, |
||||||
|
TestMessage::class); |
||||||
|
$m->setRepeatedMessage($repeated_message); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testMapFieldWrongTypeFail() |
||||||
|
{ |
||||||
|
$m = new TestMessage(); |
||||||
|
$a = 1; |
||||||
|
$m->setMapInt32Int32($a); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testMapFieldWrongObjectFail() |
||||||
|
{ |
||||||
|
$m = new TestMessage(); |
||||||
|
$m->setMapInt32Int32($m); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testMapFieldWrongRepeatedTypeFail() |
||||||
|
{ |
||||||
|
$m = new TestMessage(); |
||||||
|
|
||||||
|
$map_uint32_uint32 = new MapField(GPBType::UINT32, GPBType::UINT32); |
||||||
|
$m->setMapInt32Int32($map_uint32_uint32); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testMapFieldWrongRepeatedMessageClassFail() |
||||||
|
{ |
||||||
|
$m = new TestMessage(); |
||||||
|
|
||||||
|
$map_int32_message = new MapField(GPBType::INT32, |
||||||
|
GPBType::MESSAGE, |
||||||
|
TestMessage::class); |
||||||
|
$m->setMapInt32Message($map_int32_message); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testMessageMergeFromInvalidTypeFail() |
||||||
|
{ |
||||||
|
$m = new TestMessage(); |
||||||
|
$n = new TestMessage_Sub(); |
||||||
|
$m->mergeFrom($n); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testInt32SetStringKeyFail() |
||||||
|
{ |
||||||
|
$arr = new MapField(GPBType::INT32, GPBType::INT32); |
||||||
|
$arr['abc'] = 0; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testInt32SetStringValueFail() |
||||||
|
{ |
||||||
|
$arr = new MapField(GPBType::INT32, GPBType::INT32); |
||||||
|
$arr[0] = 'abc'; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testInt32SetMessageKeyFail() |
||||||
|
{ |
||||||
|
$arr = new MapField(GPBType::INT32, GPBType::INT32); |
||||||
|
$arr[new TestMessage_Sub()] = 0; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testInt32SetMessageValueFail() |
||||||
|
{ |
||||||
|
$arr = new MapField(GPBType::INT32, GPBType::INT32); |
||||||
|
$arr[0] = new TestMessage_Sub(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testUint32SetStringKeyFail() |
||||||
|
{ |
||||||
|
$arr = new MapField(GPBType::UINT32, GPBType::UINT32); |
||||||
|
$arr['abc'] = 0; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testUint32SetStringValueFail() |
||||||
|
{ |
||||||
|
$arr = new MapField(GPBType::UINT32, GPBType::UINT32); |
||||||
|
$arr[0] = 'abc'; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testUint32SetMessageKeyFail() |
||||||
|
{ |
||||||
|
$arr = new MapField(GPBType::UINT32, GPBType::UINT32); |
||||||
|
$arr[new TestMessage_Sub()] = 0; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testUint32SetMessageValueFail() |
||||||
|
{ |
||||||
|
$arr = new MapField(GPBType::UINT32, GPBType::UINT32); |
||||||
|
$arr[0] = new TestMessage_Sub(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testInt64SetStringKeyFail() |
||||||
|
{ |
||||||
|
$arr = new MapField(GPBType::INT64, GPBType::INT64); |
||||||
|
$arr['abc'] = 0; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testInt64SetStringValueFail() |
||||||
|
{ |
||||||
|
$arr = new MapField(GPBType::INT64, GPBType::INT64); |
||||||
|
$arr[0] = 'abc'; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testInt64SetMessageKeyFail() |
||||||
|
{ |
||||||
|
$arr = new MapField(GPBType::INT64, GPBType::INT64); |
||||||
|
$arr[new TestMessage_Sub()] = 0; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testInt64SetMessageValueFail() |
||||||
|
{ |
||||||
|
$arr = new MapField(GPBType::INT64, GPBType::INT64); |
||||||
|
$arr[0] = new TestMessage_Sub(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testUint64SetStringKeyFail() |
||||||
|
{ |
||||||
|
$arr = new MapField(GPBType::UINT64, GPBType::UINT64); |
||||||
|
$arr['abc'] = 0; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testUint64SetStringValueFail() |
||||||
|
{ |
||||||
|
$arr = new MapField(GPBType::UINT64, GPBType::UINT64); |
||||||
|
$arr[0] = 'abc'; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testUint64SetMessageKeyFail() |
||||||
|
{ |
||||||
|
$arr = new MapField(GPBType::UINT64, GPBType::UINT64); |
||||||
|
$arr[new TestMessage_Sub()] = 0; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testUint64SetMessageValueFail() |
||||||
|
{ |
||||||
|
$arr = new MapField(GPBType::UINT64, GPBType::UINT64); |
||||||
|
$arr[0] = new TestMessage_Sub(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testDoubleSetStringValueFail() |
||||||
|
{ |
||||||
|
$arr = new MapField(GPBType::INT64, GPBType::DOUBLE); |
||||||
|
$arr[0] = 'abc'; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testDoubleSetMessageValueFail() |
||||||
|
{ |
||||||
|
$arr = new MapField(GPBType::INT64, GPBType::DOUBLE); |
||||||
|
$arr[0] = new TestMessage_Sub(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testBoolSetMessageKeyFail() |
||||||
|
{ |
||||||
|
$arr = new MapField(GPBType::BOOL, GPBType::BOOL); |
||||||
|
$arr[new TestMessage_Sub()] = true; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testBoolSetMessageValueFail() |
||||||
|
{ |
||||||
|
$arr = new MapField(GPBType::BOOL, GPBType::BOOL); |
||||||
|
$arr[true] = new TestMessage_Sub(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testStringSetInvalidUTF8KeyFail() |
||||||
|
{ |
||||||
|
$arr = new MapField(GPBType::STRING, GPBType::STRING); |
||||||
|
$arr[hex2bin("ff")] = 'abc'; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testStringSetInvalidUTF8ValueFail() |
||||||
|
{ |
||||||
|
$arr = new MapField(GPBType::STRING, GPBType::STRING); |
||||||
|
$arr['abc'] = hex2bin("ff"); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testStringSetMessageKeyFail() |
||||||
|
{ |
||||||
|
$arr = new MapField(GPBType::STRING, GPBType::STRING); |
||||||
|
$arr[new TestMessage_Sub()] = 'abc'; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testStringSetMessageValueFail() |
||||||
|
{ |
||||||
|
$arr = new MapField(GPBType::STRING, GPBType::STRING); |
||||||
|
$arr['abc'] = new TestMessage_Sub(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testMessageSetIntValueFail() |
||||||
|
{ |
||||||
|
$arr = |
||||||
|
new MapField(GPBType::INT32, GPBType::MESSAGE, TestMessage::class); |
||||||
|
$arr[0] = 0; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testMessageSetStringValueFail() |
||||||
|
{ |
||||||
|
$arr = |
||||||
|
new MapField(GPBType::INT32, GPBType::MESSAGE, TestMessage::class); |
||||||
|
$arr[0] = 'abc'; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException PHPUnit_Framework_Error |
||||||
|
*/ |
||||||
|
public function testMessageSetOtherMessageValueFail() |
||||||
|
{ |
||||||
|
$arr = |
||||||
|
new MapField(GPBType::INT32, GPBType::MESSAGE, TestMessage::class); |
||||||
|
$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; |
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue