Parcourir la source

Make php message class final to avoid mocking (#6277)

* Make php message class final

Because proto messages are just data object, they should not be mocked.
Explicitly make them final to avoid accidental usage.

* Update generated descriptors
Paul Yang il y a 6 ans
Parent
commit
7f84a94366
29 fichiers modifiés avec 28 ajouts et 28 suppressions
  1. BIN
      csharp/src/Google.Protobuf.Test/testprotos.pb
  2. 1 1
      php/src/Google/Protobuf/Internal/DescriptorProto.php
  3. 1 1
      php/src/Google/Protobuf/Internal/DescriptorProto/ExtensionRange.php
  4. 1 1
      php/src/Google/Protobuf/Internal/DescriptorProto/ReservedRange.php
  5. 1 1
      php/src/Google/Protobuf/Internal/EnumDescriptorProto.php
  6. 1 1
      php/src/Google/Protobuf/Internal/EnumDescriptorProto/EnumReservedRange.php
  7. 1 1
      php/src/Google/Protobuf/Internal/EnumOptions.php
  8. 1 1
      php/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php
  9. 1 1
      php/src/Google/Protobuf/Internal/EnumValueOptions.php
  10. 1 1
      php/src/Google/Protobuf/Internal/ExtensionRangeOptions.php
  11. 1 1
      php/src/Google/Protobuf/Internal/FieldDescriptorProto.php
  12. 1 1
      php/src/Google/Protobuf/Internal/FieldOptions.php
  13. 1 1
      php/src/Google/Protobuf/Internal/FileDescriptorProto.php
  14. 1 1
      php/src/Google/Protobuf/Internal/FileDescriptorSet.php
  15. 1 1
      php/src/Google/Protobuf/Internal/FileOptions.php
  16. 1 1
      php/src/Google/Protobuf/Internal/GeneratedCodeInfo.php
  17. 1 1
      php/src/Google/Protobuf/Internal/GeneratedCodeInfo/Annotation.php
  18. 1 1
      php/src/Google/Protobuf/Internal/MessageOptions.php
  19. 1 1
      php/src/Google/Protobuf/Internal/MethodDescriptorProto.php
  20. 1 1
      php/src/Google/Protobuf/Internal/MethodOptions.php
  21. 1 1
      php/src/Google/Protobuf/Internal/OneofDescriptorProto.php
  22. 1 1
      php/src/Google/Protobuf/Internal/OneofOptions.php
  23. 1 1
      php/src/Google/Protobuf/Internal/ServiceDescriptorProto.php
  24. 1 1
      php/src/Google/Protobuf/Internal/ServiceOptions.php
  25. 1 1
      php/src/Google/Protobuf/Internal/SourceCodeInfo.php
  26. 1 1
      php/src/Google/Protobuf/Internal/SourceCodeInfo/Location.php
  27. 1 1
      php/src/Google/Protobuf/Internal/UninterpretedOption.php
  28. 1 1
      php/src/Google/Protobuf/Internal/UninterpretedOption/NamePart.php
  29. 1 1
      src/google/protobuf/compiler/php/php_generator.cc

BIN
csharp/src/Google.Protobuf.Test/testprotos.pb


+ 1 - 1
php/src/Google/Protobuf/Internal/DescriptorProto.php

@@ -15,7 +15,7 @@ use Google\Protobuf\Internal\GPBUtil;
  *
  * Generated from protobuf message <code>google.protobuf.DescriptorProto</code>
  */
-class DescriptorProto extends \Google\Protobuf\Internal\Message
+final class DescriptorProto extends \Google\Protobuf\Internal\Message
 {
     /**
      * Generated from protobuf field <code>optional string name = 1;</code>

+ 1 - 1
php/src/Google/Protobuf/Internal/DescriptorProto/ExtensionRange.php

@@ -13,7 +13,7 @@ use Google\Protobuf\Internal\GPBUtil;
 /**
  * Generated from protobuf message <code>google.protobuf.DescriptorProto.ExtensionRange</code>
  */
-class ExtensionRange extends \Google\Protobuf\Internal\Message
+final class ExtensionRange extends \Google\Protobuf\Internal\Message
 {
     /**
      * Inclusive.

+ 1 - 1
php/src/Google/Protobuf/Internal/DescriptorProto/ReservedRange.php

@@ -17,7 +17,7 @@ use Google\Protobuf\Internal\GPBUtil;
  *
  * Generated from protobuf message <code>google.protobuf.DescriptorProto.ReservedRange</code>
  */
-class ReservedRange extends \Google\Protobuf\Internal\Message
+final class ReservedRange extends \Google\Protobuf\Internal\Message
 {
     /**
      * Inclusive.

+ 1 - 1
php/src/Google/Protobuf/Internal/EnumDescriptorProto.php

@@ -15,7 +15,7 @@ use Google\Protobuf\Internal\GPBUtil;
  *
  * Generated from protobuf message <code>google.protobuf.EnumDescriptorProto</code>
  */
-class EnumDescriptorProto extends \Google\Protobuf\Internal\Message
+final class EnumDescriptorProto extends \Google\Protobuf\Internal\Message
 {
     /**
      * Generated from protobuf field <code>optional string name = 1;</code>

+ 1 - 1
php/src/Google/Protobuf/Internal/EnumDescriptorProto/EnumReservedRange.php

@@ -19,7 +19,7 @@ use Google\Protobuf\Internal\GPBUtil;
  *
  * Generated from protobuf message <code>google.protobuf.EnumDescriptorProto.EnumReservedRange</code>
  */
-class EnumReservedRange extends \Google\Protobuf\Internal\Message
+final class EnumReservedRange extends \Google\Protobuf\Internal\Message
 {
     /**
      * Inclusive.

+ 1 - 1
php/src/Google/Protobuf/Internal/EnumOptions.php

@@ -13,7 +13,7 @@ use Google\Protobuf\Internal\GPBUtil;
 /**
  * Generated from protobuf message <code>google.protobuf.EnumOptions</code>
  */
-class EnumOptions extends \Google\Protobuf\Internal\Message
+final class EnumOptions extends \Google\Protobuf\Internal\Message
 {
     /**
      * Set this option to true to allow mapping different tag names to the same

+ 1 - 1
php/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php

@@ -15,7 +15,7 @@ use Google\Protobuf\Internal\GPBUtil;
  *
  * Generated from protobuf message <code>google.protobuf.EnumValueDescriptorProto</code>
  */
-class EnumValueDescriptorProto extends \Google\Protobuf\Internal\Message
+final class EnumValueDescriptorProto extends \Google\Protobuf\Internal\Message
 {
     /**
      * Generated from protobuf field <code>optional string name = 1;</code>

+ 1 - 1
php/src/Google/Protobuf/Internal/EnumValueOptions.php

@@ -13,7 +13,7 @@ use Google\Protobuf\Internal\GPBUtil;
 /**
  * Generated from protobuf message <code>google.protobuf.EnumValueOptions</code>
  */
-class EnumValueOptions extends \Google\Protobuf\Internal\Message
+final class EnumValueOptions extends \Google\Protobuf\Internal\Message
 {
     /**
      * Is this enum value deprecated?

+ 1 - 1
php/src/Google/Protobuf/Internal/ExtensionRangeOptions.php

@@ -13,7 +13,7 @@ use Google\Protobuf\Internal\GPBUtil;
 /**
  * Generated from protobuf message <code>google.protobuf.ExtensionRangeOptions</code>
  */
-class ExtensionRangeOptions extends \Google\Protobuf\Internal\Message
+final class ExtensionRangeOptions extends \Google\Protobuf\Internal\Message
 {
     /**
      * The parser stores options it doesn't recognize here. See above.

+ 1 - 1
php/src/Google/Protobuf/Internal/FieldDescriptorProto.php

@@ -15,7 +15,7 @@ use Google\Protobuf\Internal\GPBUtil;
  *
  * Generated from protobuf message <code>google.protobuf.FieldDescriptorProto</code>
  */
-class FieldDescriptorProto extends \Google\Protobuf\Internal\Message
+final class FieldDescriptorProto extends \Google\Protobuf\Internal\Message
 {
     /**
      * Generated from protobuf field <code>optional string name = 1;</code>

+ 1 - 1
php/src/Google/Protobuf/Internal/FieldOptions.php

@@ -13,7 +13,7 @@ use Google\Protobuf\Internal\GPBUtil;
 /**
  * Generated from protobuf message <code>google.protobuf.FieldOptions</code>
  */
-class FieldOptions extends \Google\Protobuf\Internal\Message
+final class FieldOptions extends \Google\Protobuf\Internal\Message
 {
     /**
      * The ctype option instructs the C++ code generator to use a different

+ 1 - 1
php/src/Google/Protobuf/Internal/FileDescriptorProto.php

@@ -15,7 +15,7 @@ use Google\Protobuf\Internal\GPBUtil;
  *
  * Generated from protobuf message <code>google.protobuf.FileDescriptorProto</code>
  */
-class FileDescriptorProto extends \Google\Protobuf\Internal\Message
+final class FileDescriptorProto extends \Google\Protobuf\Internal\Message
 {
     /**
      * file name, relative to root of source tree

+ 1 - 1
php/src/Google/Protobuf/Internal/FileDescriptorSet.php

@@ -16,7 +16,7 @@ use Google\Protobuf\Internal\GPBUtil;
  *
  * Generated from protobuf message <code>google.protobuf.FileDescriptorSet</code>
  */
-class FileDescriptorSet extends \Google\Protobuf\Internal\Message
+final class FileDescriptorSet extends \Google\Protobuf\Internal\Message
 {
     /**
      * Generated from protobuf field <code>repeated .google.protobuf.FileDescriptorProto file = 1;</code>

+ 1 - 1
php/src/Google/Protobuf/Internal/FileOptions.php

@@ -13,7 +13,7 @@ use Google\Protobuf\Internal\GPBUtil;
 /**
  * Generated from protobuf message <code>google.protobuf.FileOptions</code>
  */
-class FileOptions extends \Google\Protobuf\Internal\Message
+final class FileOptions extends \Google\Protobuf\Internal\Message
 {
     /**
      * Sets the Java package where classes generated from this .proto will be

+ 1 - 1
php/src/Google/Protobuf/Internal/GeneratedCodeInfo.php

@@ -17,7 +17,7 @@ use Google\Protobuf\Internal\GPBUtil;
  *
  * Generated from protobuf message <code>google.protobuf.GeneratedCodeInfo</code>
  */
-class GeneratedCodeInfo extends \Google\Protobuf\Internal\Message
+final class GeneratedCodeInfo extends \Google\Protobuf\Internal\Message
 {
     /**
      * An Annotation connects some span of text in generated code to an element

+ 1 - 1
php/src/Google/Protobuf/Internal/GeneratedCodeInfo/Annotation.php

@@ -13,7 +13,7 @@ use Google\Protobuf\Internal\GPBUtil;
 /**
  * Generated from protobuf message <code>google.protobuf.GeneratedCodeInfo.Annotation</code>
  */
-class Annotation extends \Google\Protobuf\Internal\Message
+final class Annotation extends \Google\Protobuf\Internal\Message
 {
     /**
      * Identifies the element in the original source .proto file. This field

+ 1 - 1
php/src/Google/Protobuf/Internal/MessageOptions.php

@@ -13,7 +13,7 @@ use Google\Protobuf\Internal\GPBUtil;
 /**
  * Generated from protobuf message <code>google.protobuf.MessageOptions</code>
  */
-class MessageOptions extends \Google\Protobuf\Internal\Message
+final class MessageOptions extends \Google\Protobuf\Internal\Message
 {
     /**
      * Set true to use the old proto1 MessageSet wire format for extensions.

+ 1 - 1
php/src/Google/Protobuf/Internal/MethodDescriptorProto.php

@@ -15,7 +15,7 @@ use Google\Protobuf\Internal\GPBUtil;
  *
  * Generated from protobuf message <code>google.protobuf.MethodDescriptorProto</code>
  */
-class MethodDescriptorProto extends \Google\Protobuf\Internal\Message
+final class MethodDescriptorProto extends \Google\Protobuf\Internal\Message
 {
     /**
      * Generated from protobuf field <code>optional string name = 1;</code>

+ 1 - 1
php/src/Google/Protobuf/Internal/MethodOptions.php

@@ -13,7 +13,7 @@ use Google\Protobuf\Internal\GPBUtil;
 /**
  * Generated from protobuf message <code>google.protobuf.MethodOptions</code>
  */
-class MethodOptions extends \Google\Protobuf\Internal\Message
+final class MethodOptions extends \Google\Protobuf\Internal\Message
 {
     /**
      * Is this method deprecated?

+ 1 - 1
php/src/Google/Protobuf/Internal/OneofDescriptorProto.php

@@ -15,7 +15,7 @@ use Google\Protobuf\Internal\GPBUtil;
  *
  * Generated from protobuf message <code>google.protobuf.OneofDescriptorProto</code>
  */
-class OneofDescriptorProto extends \Google\Protobuf\Internal\Message
+final class OneofDescriptorProto extends \Google\Protobuf\Internal\Message
 {
     /**
      * Generated from protobuf field <code>optional string name = 1;</code>

+ 1 - 1
php/src/Google/Protobuf/Internal/OneofOptions.php

@@ -13,7 +13,7 @@ use Google\Protobuf\Internal\GPBUtil;
 /**
  * Generated from protobuf message <code>google.protobuf.OneofOptions</code>
  */
-class OneofOptions extends \Google\Protobuf\Internal\Message
+final class OneofOptions extends \Google\Protobuf\Internal\Message
 {
     /**
      * The parser stores options it doesn't recognize here. See above.

+ 1 - 1
php/src/Google/Protobuf/Internal/ServiceDescriptorProto.php

@@ -15,7 +15,7 @@ use Google\Protobuf\Internal\GPBUtil;
  *
  * Generated from protobuf message <code>google.protobuf.ServiceDescriptorProto</code>
  */
-class ServiceDescriptorProto extends \Google\Protobuf\Internal\Message
+final class ServiceDescriptorProto extends \Google\Protobuf\Internal\Message
 {
     /**
      * Generated from protobuf field <code>optional string name = 1;</code>

+ 1 - 1
php/src/Google/Protobuf/Internal/ServiceOptions.php

@@ -13,7 +13,7 @@ use Google\Protobuf\Internal\GPBUtil;
 /**
  * Generated from protobuf message <code>google.protobuf.ServiceOptions</code>
  */
-class ServiceOptions extends \Google\Protobuf\Internal\Message
+final class ServiceOptions extends \Google\Protobuf\Internal\Message
 {
     /**
      * Is this service deprecated?

+ 1 - 1
php/src/Google/Protobuf/Internal/SourceCodeInfo.php

@@ -16,7 +16,7 @@ use Google\Protobuf\Internal\GPBUtil;
  *
  * Generated from protobuf message <code>google.protobuf.SourceCodeInfo</code>
  */
-class SourceCodeInfo extends \Google\Protobuf\Internal\Message
+final class SourceCodeInfo extends \Google\Protobuf\Internal\Message
 {
     /**
      * A Location identifies a piece of source code in a .proto file which

+ 1 - 1
php/src/Google/Protobuf/Internal/SourceCodeInfo/Location.php

@@ -13,7 +13,7 @@ use Google\Protobuf\Internal\GPBUtil;
 /**
  * Generated from protobuf message <code>google.protobuf.SourceCodeInfo.Location</code>
  */
-class Location extends \Google\Protobuf\Internal\Message
+final class Location extends \Google\Protobuf\Internal\Message
 {
     /**
      * Identifies which part of the FileDescriptorProto was defined at this

+ 1 - 1
php/src/Google/Protobuf/Internal/UninterpretedOption.php

@@ -20,7 +20,7 @@ use Google\Protobuf\Internal\GPBUtil;
  *
  * Generated from protobuf message <code>google.protobuf.UninterpretedOption</code>
  */
-class UninterpretedOption extends \Google\Protobuf\Internal\Message
+final class UninterpretedOption extends \Google\Protobuf\Internal\Message
 {
     /**
      * Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption.NamePart name = 2;</code>

+ 1 - 1
php/src/Google/Protobuf/Internal/UninterpretedOption/NamePart.php

@@ -19,7 +19,7 @@ use Google\Protobuf\Internal\GPBUtil;
  *
  * Generated from protobuf message <code>google.protobuf.UninterpretedOption.NamePart</code>
  */
-class NamePart extends \Google\Protobuf\Internal\Message
+final class NamePart extends \Google\Protobuf\Internal\Message
 {
     /**
      * Generated from protobuf field <code>required string name_part = 1;</code>

+ 1 - 1
src/google/protobuf/compiler/php/php_generator.cc

@@ -1307,7 +1307,7 @@ void GenerateMessageFile(const FileDescriptor* file, const Descriptor* message,
   }
 
   printer.Print(
-      "class ^name^ extends \\Google\\Protobuf\\Internal\\Message\n"
+      "final class ^name^ extends \\Google\\Protobuf\\Internal\\Message\n"
       "{\n",
       "name", fullname);
   Indent(&printer);