InsertOneTest.php 1.27 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\InsertOne;

class InsertOneTest extends TestCase
{
    /**
11
     * @dataProvider provideInvalidDocumentValues
12
     */
13
    public function testConstructorDocumentArgumentTypeCheck($document)
14
    {
15
        $this->expectException(InvalidArgumentException::class);
16 17 18 19
        new InsertOne($this->getDatabaseName(), $this->getCollectionName(), $document);
    }

    /**
20
     * @dataProvider provideInvalidConstructorOptions
21
     */
22
    public function testConstructorOptionTypeChecks(array $options)
23
    {
24
        $this->expectException(InvalidArgumentException::class);
Jeremy Mikola's avatar
Jeremy Mikola committed
25
        new InsertOne($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], $options);
26 27 28 29
    }

    public function provideInvalidConstructorOptions()
    {
Jeremy Mikola's avatar
Jeremy Mikola committed
30
        $options = [];
31

32 33 34 35
        foreach ($this->getInvalidBooleanValues() as $value) {
            $options[][] = ['bypassDocumentValidation' => $value];
        }

36 37 38 39
        foreach ($this->getInvalidSessionValues() as $value) {
            $options[][] = ['session' => $value];
        }

40
        foreach ($this->getInvalidWriteConcernValues() as $value) {
Jeremy Mikola's avatar
Jeremy Mikola committed
41
            $options[][] = ['writeConcern' => $value];
42 43 44
        }

        return $options;
45 46
    }
}