-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trigger warning when calling CodecCursor::setTypeMap
- Loading branch information
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
namespace MongoDB\Tests\Model; | ||
|
||
use MongoDB\BSON\Document; | ||
use MongoDB\Codec\DocumentCodec; | ||
use MongoDB\Model\CodecCursor; | ||
use MongoDB\Tests\FunctionalTestCase; | ||
|
||
class CodecCursorFunctionalTest extends FunctionalTestCase | ||
{ | ||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->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([]); | ||
} | ||
}; | ||
} | ||
} |