-
Notifications
You must be signed in to change notification settings - Fork 16.1k
feat(php): support default values for editions/proto2 #25161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
bshaffer
wants to merge
9
commits into
protocolbuffers:main
from
bshaffer:php-fix-ignored-default-fields
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e0a894b
feat(php): support default values for editions/proto2
bshaffer 5f641bc
add support editions as a php feature
bshaffer 32845b4
fix namespace
bshaffer f556bdd
fix tests to expect strings for 32-bit platforms
bshaffer 2ec2aed
fixes for 32-bit system - adds GPBUtil::compatibleInt64
bshaffer ebd7e55
fix compatibleInt64, add it to the extension
bshaffer 6087ede
fix c-extension GPBUtil::compatibleInt64
bshaffer 7b3d966
adds DefaultForFieldWithPresence
bshaffer 16706c0
add getter check
bshaffer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| <?php | ||
|
|
||
| require_once('test_base.php'); | ||
|
|
||
| use Default_value\TestDefaultValue; | ||
| use Default_value\TestEnum; | ||
|
|
||
| class DefaultValueTest extends TestBase | ||
| { | ||
| public function testDefaultValues() | ||
| { | ||
| $message = new TestDefaultValue(); | ||
|
|
||
| $this->assertSame(1, $message->getOptionalInt32()); | ||
| if (PHP_INT_SIZE == 4) { | ||
| $this->assertSame('2', $message->getOptionalInt64()); | ||
| } else { | ||
| $this->assertSame(2, $message->getOptionalInt64()); | ||
| } | ||
| $this->assertSame(3, $message->getOptionalUint32()); | ||
| if (PHP_INT_SIZE == 4) { | ||
| $this->assertSame('4', $message->getOptionalUint64()); | ||
| } else { | ||
| $this->assertSame(4, $message->getOptionalUint64()); | ||
| } | ||
| $this->assertSame(5.5, $message->getOptionalFloat()); | ||
| $this->assertSame(6.6, $message->getOptionalDouble()); | ||
| $this->assertSame(true, $message->getOptionalBool()); | ||
| $this->assertSame("hello", $message->getOptionalString()); | ||
| $this->assertSame("world", $message->getOptionalBytes()); | ||
| $this->assertSame(TestEnum::HELLO, $message->getOptionalEnum()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| edition = "2023"; | ||
|
|
||
| package default_value; | ||
|
|
||
| message TestDefaultValue { | ||
| int32 optional_int32 = 1 [default = 1]; | ||
| int64 optional_int64 = 2 [default = 2]; | ||
| uint32 optional_uint32 = 3 [default = 3]; | ||
| uint64 optional_uint64 = 4 [default = 4]; | ||
| float optional_float = 5 [default = 5.5]; | ||
| double optional_double = 6 [default = 6.6]; | ||
| bool optional_bool = 7 [default = true]; | ||
| string optional_string = 8 [default = "hello"]; | ||
| bytes optional_bytes = 9 [default = "world"]; | ||
| TestEnum optional_enum = 10 [default = HELLO]; | ||
| } | ||
|
|
||
| enum TestEnum { | ||
| DEFAULT = 0; | ||
| HELLO = 1; | ||
| WORLD = 2; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be unreachable, might as well ABSL_CHECK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like this?