diff --git a/src/Model/BSONDocument.php b/src/Model/BSONDocument.php index b9a9c0d80..1ff8bc1e6 100644 --- a/src/Model/BSONDocument.php +++ b/src/Model/BSONDocument.php @@ -52,10 +52,10 @@ public function __clone() * by default. * * @see https://php.net/arrayobject.construct - * @param array $input + * @param array|stdClass $input * @psalm-param class-string>|class-string> $iteratorClass */ - public function __construct(array $input = [], int $flags = ArrayObject::ARRAY_AS_PROPS, string $iteratorClass = ArrayIterator::class) + public function __construct(array|stdClass $input = [], int $flags = ArrayObject::ARRAY_AS_PROPS, string $iteratorClass = ArrayIterator::class) { parent::__construct($input, $flags, $iteratorClass); } diff --git a/tests/Model/BSONDocumentTest.php b/tests/Model/BSONDocumentTest.php index 4d832d591..2000aef63 100644 --- a/tests/Model/BSONDocumentTest.php +++ b/tests/Model/BSONDocumentTest.php @@ -23,6 +23,13 @@ public function testConstructorDefaultsToPropertyAccess(): void $this->assertSame('bar', $document->foo); } + public function testConstructorWithStandardObject(): void + { + $object = (object) ['foo' => 'bar']; + $document = new BSONDocument($object); + $this->assertEquals($object, $document->bsonSerialize()); + } + public function testBsonSerializeCastsToObject(): void { $data = [0 => 'foo', 2 => 'bar'];