Skip to content

Commit 8abcce5

Browse files
committed
BSONDocument should only accept stdClass
1 parent 4d4132e commit 8abcce5

File tree

2 files changed

+5
-14
lines changed

2 files changed

+5
-14
lines changed

src/Model/BSONDocument.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ public function __clone()
5252
* by default.
5353
*
5454
* @see https://php.net/arrayobject.construct
55-
* @param object|array<string, mixed> $input
55+
* @param array<string, mixed>|stdClass $input
5656
* @psalm-param class-string<ArrayIterator<string,mixed>>|class-string<ArrayObject<string,mixed>> $iteratorClass
5757
*/
58-
public function __construct(array|object $input = [], int $flags = ArrayObject::ARRAY_AS_PROPS, string $iteratorClass = ArrayIterator::class)
58+
public function __construct(array|stdClass $input = [], int $flags = ArrayObject::ARRAY_AS_PROPS, string $iteratorClass = ArrayIterator::class)
5959
{
6060
parent::__construct($input, $flags, $iteratorClass);
6161
}

tests/Model/BSONDocumentTest.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,9 @@ public function testConstructorDefaultsToPropertyAccess(): void
2525

2626
public function testConstructorWithStandardObject(): void
2727
{
28-
$document = new BSONDocument((object) ['foo' => 'bar']);
29-
$this->assertSame('bar', $document->foo);
30-
}
31-
32-
public function testConstructorWithClassObject(): void
33-
{
34-
$document = new BSONDocument(new class () {
35-
public string $foo = 'bar';
36-
protected string $baz = 'qux';
37-
});
38-
$this->assertSame('bar', $document->foo);
39-
$this->assertObjectNotHasProperty('baz', $document);
28+
$object = (object) ['foo' => 'bar'];
29+
$document = new BSONDocument($object);
30+
$this->assertEquals($object, $document->bsonSerialize());
4031
}
4132

4233
public function testBsonSerializeCastsToObject(): void

0 commit comments

Comments
 (0)