diff --git a/src/Model/CodecCursor.php b/src/Model/CodecCursor.php index c4c9e9b97..b3b5061ae 100644 --- a/src/Model/CodecCursor.php +++ b/src/Model/CodecCursor.php @@ -27,6 +27,10 @@ use function assert; use function iterator_to_array; +use function sprintf; +use function trigger_error; + +use const E_USER_WARNING; /** * @template TValue of object @@ -104,6 +108,7 @@ public function rewind(): void public function setTypeMap(array $typemap): void { // Not supported + trigger_error(sprintf('Discarding type map for %s', __METHOD__), E_USER_WARNING); } /** @return array */ diff --git a/tests/Model/CodecCursorFunctionalTest.php b/tests/Model/CodecCursorFunctionalTest.php new file mode 100644 index 000000000..47d301e04 --- /dev/null +++ b/tests/Model/CodecCursorFunctionalTest.php @@ -0,0 +1,66 @@ +dropCollection($this->getDatabaseName(), $this->getCollectionName()); + } + + public function testSetTypeMap(): void + { + $collection = self::createTestClient()->selectCollection($this->getDatabaseName(), $this->getCollectionName()); + $cursor = $collection->find(); + + $codecCursor = CodecCursor::fromCursor($cursor, $this->createCodec()); + + $this->expectWarning(); + $this->expectWarningMessage('Discarding type map for MongoDB\Model\CodecCursor::setTypeMap'); + + $codecCursor->setTypeMap(['root' => 'array']); + } + + private function createCodec(): DocumentCodec + { + return new class implements DocumentCodec { + public function canDecode($value): bool + { + return false; + } + + public function canEncode($value): bool + { + return false; + } + + public function decode($value): object + { + return (object) []; + } + + public function decodeIfSupported($value): object + { + return (object) []; + } + + public function encode($value): Document + { + return Document::fromPHP([]); + } + + public function encodeIfSupported($value): Document + { + return Document::fromPHP([]); + } + }; + } +}