|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace MongoDB\Tests\Operation; |
| 4 | + |
| 5 | +use MongoDB\Operation\FindOneAndReplace; |
| 6 | + |
| 7 | +class FindOneAndReplaceTest extends TestCase |
| 8 | +{ |
| 9 | + /** |
| 10 | + * @expectedException MongoDB\Exception\InvalidArgumentTypeException |
| 11 | + * @dataProvider provideInvalidDocumentValues |
| 12 | + */ |
| 13 | + public function testConstructorFilterArgumentTypeCheck($filter) |
| 14 | + { |
| 15 | + new FindOneAndReplace($this->getDatabaseName(), $this->getCollectionName(), $filter, []); |
| 16 | + } |
| 17 | + |
| 18 | + /** |
| 19 | + * @expectedException MongoDB\Exception\InvalidArgumentTypeException |
| 20 | + * @dataProvider provideInvalidDocumentValues |
| 21 | + */ |
| 22 | + public function testConstructorReplacementArgumentTypeCheck($replacement) |
| 23 | + { |
| 24 | + new FindOneAndReplace($this->getDatabaseName(), $this->getCollectionName(), [], $replacement); |
| 25 | + } |
| 26 | + |
| 27 | + /** |
| 28 | + * @expectedException MongoDB\Exception\InvalidArgumentException |
| 29 | + * @expectedExceptionMessage First key in $replacement argument is an update operator |
| 30 | + */ |
| 31 | + public function testConstructorReplacementArgumentRequiresNoOperators() |
| 32 | + { |
| 33 | + new FindOneAndReplace($this->getDatabaseName(), $this->getCollectionName(), [], ['$set' => ['x' => 1]]); |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * @expectedException MongoDB\Exception\InvalidArgumentTypeException |
| 38 | + * @dataProvider provideInvalidConstructorOptions |
| 39 | + */ |
| 40 | + public function testConstructorOptionTypeChecks(array $options) |
| 41 | + { |
| 42 | + new FindOneAndReplace($this->getDatabaseName(), $this->getCollectionName(), [], [], $options); |
| 43 | + } |
| 44 | + |
| 45 | + public function provideInvalidConstructorOptions() |
| 46 | + { |
| 47 | + $options = []; |
| 48 | + |
| 49 | + foreach ($this->getInvalidDocumentValues() as $value) { |
| 50 | + $options[][] = ['projection' => $value]; |
| 51 | + } |
| 52 | + |
| 53 | + foreach ($this->getInvalidIntegerValues() as $value) { |
| 54 | + $options[][] = ['returnDocument' => $value]; |
| 55 | + } |
| 56 | + |
| 57 | + return $options; |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * @expectedException MongoDB\Exception\InvalidArgumentException |
| 62 | + * @dataProvider provideInvalidConstructorReturnDocumentOptions |
| 63 | + */ |
| 64 | + public function testConstructorReturnDocumentOption($returnDocument) |
| 65 | + { |
| 66 | + new FindOneAndReplace($this->getDatabaseName(), $this->getCollectionName(), [], [], ['returnDocument' => $returnDocument]); |
| 67 | + } |
| 68 | + |
| 69 | + public function provideInvalidConstructorReturnDocumentOptions() |
| 70 | + { |
| 71 | + return $this->wrapValuesForDataProvider([-1, 0, 3]); |
| 72 | + } |
| 73 | +} |
0 commit comments