Skip to content

Commit

Permalink
Merge v1.x into v2.x (#1555)
Browse files Browse the repository at this point in the history
  • Loading branch information
mongodb-php-bot authored Dec 11, 2024
2 parents 4a3044b + 75f9566 commit 7c3bc10
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Model/BSONDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ public function __clone()
* by default.
*
* @see https://php.net/arrayobject.construct
* @param array<string, mixed> $input
* @param array<string, mixed>|stdClass $input
* @psalm-param class-string<ArrayIterator<string,mixed>>|class-string<ArrayObject<string,mixed>> $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);
}
Expand Down
7 changes: 7 additions & 0 deletions tests/Model/BSONDocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down

0 comments on commit 7c3bc10

Please sign in to comment.