InsertManyTest.php 1.98 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
<?php

namespace MongoDB\Tests\Operation;

use MongoDB\Operation\InsertMany;

class InsertManyTest extends TestCase
{
    /**
     * @expectedException MongoDB\Exception\InvalidArgumentException
11
     * @expectedExceptionMessage $documents is empty
12 13 14
     */
    public function testConstructorDocumentsMustNotBeEmpty()
    {
Jeremy Mikola's avatar
Jeremy Mikola committed
15
        new InsertMany($this->getDatabaseName(), $this->getCollectionName(), []);
16 17 18 19
    }

    /**
     * @expectedException MongoDB\Exception\InvalidArgumentException
20
     * @expectedExceptionMessage $documents is not a list (unexpected index: "1")
21 22 23
     */
    public function testConstructorDocumentsMustBeAList()
    {
Jeremy Mikola's avatar
Jeremy Mikola committed
24
        new InsertMany($this->getDatabaseName(), $this->getCollectionName(), [1 => ['x' => 1]]);
25 26 27
    }

    /**
28
     * @expectedException MongoDB\Exception\InvalidArgumentException
29 30
     * @expectedExceptionMessageRegExp /Expected \$documents\[0\] to have type "array or object" but found "[\w ]+"/
     * @dataProvider provideInvalidDocumentValues
31
     */
32
    public function testConstructorDocumentsArgumentElementTypeChecks($document)
33
    {
Jeremy Mikola's avatar
Jeremy Mikola committed
34
        new InsertMany($this->getDatabaseName(), $this->getCollectionName(), [$document]);
35 36 37
    }

    /**
38
     * @expectedException MongoDB\Exception\InvalidArgumentException
39
     * @dataProvider provideInvalidConstructorOptions
40
     */
41
    public function testConstructorOptionTypeChecks(array $options)
42
    {
Jeremy Mikola's avatar
Jeremy Mikola committed
43
        new InsertMany($this->getDatabaseName(), $this->getCollectionName(), [['x' => 1]], $options);
44 45
    }

46
    public function provideInvalidConstructorOptions()
47
    {
Jeremy Mikola's avatar
Jeremy Mikola committed
48
        $options = [];
49

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

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

        foreach ($this->getInvalidWriteConcernValues() as $value) {
Jeremy Mikola's avatar
Jeremy Mikola committed
59
            $options[][] = ['writeConcern' => $value];
60 61 62
        }

        return $options;
63 64
    }
}