UpdateManyTest.php 1.88 KB
Newer Older
1 2 3 4
<?php

namespace MongoDB\Tests\Operation;

5
use MongoDB\Model\BSONDocument;
6 7 8 9 10
use MongoDB\Operation\UpdateMany;

class UpdateManyTest extends TestCase
{
    /**
11
     * @expectedException MongoDB\Exception\InvalidArgumentException
12
     * @dataProvider provideInvalidDocumentValues
13
     */
14
    public function testConstructorFilterArgumentTypeCheck($filter)
15
    {
Jeremy Mikola's avatar
Jeremy Mikola committed
16
        new UpdateMany($this->getDatabaseName(), $this->getCollectionName(), $filter, ['$set' => ['x' => 1]]);
17 18 19
    }

    /**
20
     * @expectedException MongoDB\Exception\InvalidArgumentException
21
     * @dataProvider provideInvalidDocumentValues
22
     */
23
    public function testConstructorUpdateArgumentTypeCheck($update)
24
    {
Jeremy Mikola's avatar
Jeremy Mikola committed
25
        new UpdateMany($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], $update);
26 27
    }

28 29 30 31 32 33 34 35
    /**
     * @dataProvider provideUpdateDocuments
     */
    public function testConstructorUpdateArgument($update)
    {
        new UpdateMany($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], $update);
    }

36 37
    /**
     * @expectedException MongoDB\Exception\InvalidArgumentException
38
     * @expectedExceptionMessage First key in $update argument is not an update operator
39
     * @dataProvider provideReplacementDocuments
40
     */
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
    public function testConstructorUpdateArgumentRequiresOperators($replacement)
    {
        new UpdateMany($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], $replacement);
    }

    public function provideReplacementDocuments()
    {
        return $this->wrapValuesForDataProvider([
            ['y' => 1],
            (object) ['y' => 1],
            new BSONDocument(['y' => 1]),
        ]);
    }

    public function provideUpdateDocuments()
56
    {
57 58 59 60 61
        return $this->wrapValuesForDataProvider([
            ['$set' => ['y' => 1]],
            (object) ['$set' => ['y' => 1]],
            new BSONDocument(['$set' => ['y' => 1]]),
        ]);
62 63
    }
}