Skip to content

Commit

Permalink
Prohibit specifying codec and typeMap options to Watch
Browse files Browse the repository at this point in the history
  • Loading branch information
alcaeus committed Aug 23, 2023
1 parent 9cdb66a commit f532119
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Operation/Watch.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ public function __construct(Manager $manager, ?string $databaseName, ?string $co
throw InvalidArgumentException::invalidType('"codec" option', $options['codec'], DocumentCodec::class);
}

if (isset($options['codec']) && isset($options['typeMap'])) {
throw InvalidArgumentException::cannotCombineCodecAndTypeMap();
}

if (array_key_exists('fullDocument', $options) && ! is_string($options['fullDocument'])) {
throw InvalidArgumentException::invalidType('"fullDocument" option', $options['fullDocument'], 'string');
}
Expand Down
9 changes: 9 additions & 0 deletions tests/Operation/WatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Operation\Watch;
use MongoDB\Tests\Fixtures\Codec\TestDocumentCodec;
use stdClass;

/**
Expand Down Expand Up @@ -57,6 +58,14 @@ public function provideInvalidConstructorOptions()
]);
}

public function testConstructorRejectsCodecAndTypemap(): void
{
$this->expectExceptionObject(InvalidArgumentException::cannotCombineCodecAndTypeMap());

$options = ['codec' => new TestDocumentCodec(), 'typeMap' => ['root' => 'array']];
new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], $options);
}

private function getInvalidTimestampValues()
{
return [123, 3.14, 'foo', true, [], new stdClass()];
Expand Down

0 comments on commit f532119

Please sign in to comment.