UpdateTest.php 2.3 KB
Newer Older
1 2 3 4
<?php

namespace MongoDB\Tests\Operation;

5
use MongoDB\Exception\InvalidArgumentException;
6 7 8 9 10
use MongoDB\Operation\Update;

class UpdateTest extends TestCase
{
    /**
11
     * @dataProvider provideInvalidDocumentValues
12
     */
13
    public function testConstructorFilterArgumentTypeCheck($filter)
14
    {
15 16
        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessageRegExp('/Expected \$filter to have type "array or object" but found "[\w ]+"/');
Jeremy Mikola's avatar
Jeremy Mikola committed
17
        new Update($this->getDatabaseName(), $this->getCollectionName(), $filter, ['$set' => ['x' => 1]]);
18 19 20
    }

    /**
21
     * @dataProvider provideInvalidDocumentValues
22
     */
23
    public function testConstructorUpdateArgumentTypeCheck($update)
24
    {
25 26
        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessageRegExp('/Expected \$update to have type "array or object" but found "[\w ]+"/');
Jeremy Mikola's avatar
Jeremy Mikola committed
27
        new Update($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], $update);
28 29 30
    }

    /**
31
     * @dataProvider provideInvalidConstructorOptions
32
     */
33
    public function testConstructorOptionTypeChecks(array $options)
34
    {
35
        $this->expectException(InvalidArgumentException::class);
Jeremy Mikola's avatar
Jeremy Mikola committed
36
        new Update($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], ['y' => 1], $options);
37 38
    }

39
    public function provideInvalidConstructorOptions()
40
    {
Jeremy Mikola's avatar
Jeremy Mikola committed
41
        $options = [];
42

43 44 45 46
        foreach ($this->getInvalidArrayValues() as $value) {
            $options[][] = ['arrayFilters' => $value];
        }

47 48 49 50
        foreach ($this->getInvalidBooleanValues() as $value) {
            $options[][] = ['bypassDocumentValidation' => $value];
        }

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

55
        foreach ($this->getInvalidBooleanValues() as $value) {
Jeremy Mikola's avatar
Jeremy Mikola committed
56
            $options[][] = ['multi' => $value];
57 58
        }

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

63
        foreach ($this->getInvalidBooleanValues() as $value) {
Jeremy Mikola's avatar
Jeremy Mikola committed
64
            $options[][] = ['upsert' => $value];
65 66 67
        }

        foreach ($this->getInvalidWriteConcernValues() as $value) {
Jeremy Mikola's avatar
Jeremy Mikola committed
68
            $options[][] = ['writeConcern' => $value];
69 70 71
        }

        return $options;
72 73
    }
}