FindAndModifyTest.php 2.71 KB
Newer Older
1 2 3 4
<?php

namespace MongoDB\Tests\Operation;

5
use MongoDB\Exception\InvalidArgumentException;
6 7 8 9 10 11 12 13 14
use MongoDB\Operation\FindAndModify;

class FindAndModifyTest extends TestCase
{
    /**
     * @dataProvider provideInvalidConstructorOptions
     */
    public function testConstructorOptionTypeChecks(array $options)
    {
15
        $this->expectException(InvalidArgumentException::class);
16 17 18 19 20 21 22
        new FindAndModify($this->getDatabaseName(), $this->getCollectionName(), $options);
    }

    public function provideInvalidConstructorOptions()
    {
        $options = [];

23 24 25 26
        foreach ($this->getInvalidArrayValues() as $value) {
            $options[][] = ['arrayFilters' => $value];
        }

27 28 29 30
        foreach ($this->getInvalidBooleanValues() as $value) {
            $options[][] = ['bypassDocumentValidation' => $value];
        }

31 32 33 34
        foreach ($this->getInvalidDocumentValues() as $value) {
            $options[][] = ['collation' => $value];
        }

35 36 37 38 39 40 41 42
        foreach ($this->getInvalidDocumentValues() as $value) {
            $options[][] = ['fields' => $value];
        }

        foreach ($this->getInvalidIntegerValues() as $value) {
            $options[][] = ['maxTimeMS' => $value];
        }

43
        foreach ($this->getInvalidBooleanValues(true) as $value) {
44 45 46 47 48 49 50
            $options[][] = ['new' => $value];
        }

        foreach ($this->getInvalidDocumentValues() as $value) {
            $options[][] = ['query' => $value];
        }

51
        foreach ($this->getInvalidBooleanValues(true) as $value) {
52 53 54
            $options[][] = ['remove' => $value];
        }

55 56 57 58
        foreach ($this->getInvalidSessionValues() as $value) {
            $options[][] = ['session' => $value];
        }

59 60 61 62
        foreach ($this->getInvalidDocumentValues() as $value) {
            $options[][] = ['sort' => $value];
        }

63 64 65 66
        foreach ($this->getInvalidArrayValues() as $value) {
            $options[][] = ['typeMap' => $value];
        }

67 68 69 70
        foreach ($this->getInvalidDocumentValues() as $value) {
            $options[][] = ['update' => $value];
        }

71
        foreach ($this->getInvalidBooleanValues(true) as $value) {
72 73 74
            $options[][] = ['upsert' => $value];
        }

75 76 77 78
        foreach ($this->getInvalidWriteConcernValues() as $value) {
            $options[][] = ['writeConcern' => $value];
        }

79 80 81 82 83
        return $options;
    }

    public function testConstructorUpdateAndRemoveOptionsAreMutuallyExclusive()
    {
84 85
        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessage('The "remove" option must be true or an "update" document must be specified, but not both');
86 87 88
        new FindAndModify($this->getDatabaseName(), $this->getCollectionName(), ['remove' => true, 'update' => []]);
    }
}