Skip to content

Commit dacdf18

Browse files
committed
Trigger warning when calling CodecCursor::setTypeMap
1 parent 82a68e8 commit dacdf18

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/Model/CodecCursor.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727

2828
use function assert;
2929
use function iterator_to_array;
30+
use function sprintf;
31+
use function trigger_error;
32+
33+
use const E_USER_WARNING;
3034

3135
/**
3236
* @template TValue of object
@@ -104,6 +108,7 @@ public function rewind(): void
104108
public function setTypeMap(array $typemap): void
105109
{
106110
// Not supported
111+
trigger_error(sprintf('Discarding type map for %s', __METHOD__), E_USER_WARNING);
107112
}
108113

109114
/** @return array<int, TValue> */
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace MongoDB\Tests\Model;
4+
5+
use MongoDB\Codec\DocumentCodec;
6+
use MongoDB\Model\CodecCursor;
7+
use MongoDB\Tests\FunctionalTestCase;
8+
9+
class CodecCursorFunctionalTest extends FunctionalTestCase
10+
{
11+
public function setUp(): void
12+
{
13+
parent::setUp();
14+
15+
$this->dropCollection($this->getDatabaseName(), $this->getCollectionName());
16+
}
17+
18+
public function testSetTypeMap(): void
19+
{
20+
$collection = self::createTestClient()->selectCollection($this->getDatabaseName(), $this->getCollectionName());
21+
$cursor = $collection->find();
22+
23+
$codecCursor = CodecCursor::fromCursor($cursor, $this->createMock(DocumentCodec::class));
24+
25+
$this->expectWarning();
26+
$this->expectWarningMessage('Discarding type map for MongoDB\Model\CodecCursor::setTypeMap');
27+
28+
$codecCursor->setTypeMap(['root' => 'array']);
29+
}
30+
}

0 commit comments

Comments
 (0)