-
Notifications
You must be signed in to change notification settings - Fork 268
PHPLIB-1600 Accept stdClass
objects in BSONDocument
constructor
#1551
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,22 @@ public function testConstructorDefaultsToPropertyAccess(): void | |
$this->assertSame('bar', $document->foo); | ||
} | ||
|
||
public function testConstructorWithStandardObject(): void | ||
{ | ||
$document = new BSONDocument((object) ['foo' => 'bar']); | ||
$this->assertSame('bar', $document->foo); | ||
} | ||
|
||
public function testConstructorWithClassObject(): void | ||
{ | ||
$document = new BSONDocument(new class () { | ||
public string $foo = 'bar'; | ||
protected string $baz = 'qux'; | ||
}); | ||
$this->assertSame('bar', $document->foo); | ||
$this->assertObjectNotHasProperty('baz', $document); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is essentially a test of ArrayObject itself. I think it'd be preferable to test My concern is that we should preserve the same encoding behavior as the extension, which will only encodes public properties. See: https://3v4l.org/47VCv#v8.4.1 I think it's bit strange that the encoded names for protected and private properties still end up in output from If we can get away with only accepting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, I followed your suggestion on allowing only |
||
} | ||
|
||
public function testBsonSerializeCastsToObject(): void | ||
{ | ||
$data = [0 => 'foo', 2 => 'bar']; | ||
|
Uh oh!
There was an error while loading. Please reload this page.