DistinctTest.php 1.5 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\Distinct;

class DistinctTest extends TestCase
{
    /**
     * @dataProvider provideInvalidDocumentValues
     */
    public function testConstructorFilterArgumentTypeCheck($filter)
    {
15
        $this->expectException(InvalidArgumentException::class);
16 17 18 19 20 21 22 23
        new Distinct($this->getDatabaseName(), $this->getCollectionName(), 'x', $filter);
    }

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

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

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

36
        foreach ($this->getInvalidIntegerValues() as $value) {
Jeremy Mikola's avatar
Jeremy Mikola committed
37
            $options[][] = ['maxTimeMS' => $value];
38 39
        }

40 41 42 43
        foreach ($this->getInvalidReadConcernValues() as $value) {
            $options[][] = ['readConcern' => $value];
        }

44
        foreach ($this->getInvalidReadPreferenceValues() as $value) {
Jeremy Mikola's avatar
Jeremy Mikola committed
45
            $options[][] = ['readPreference' => $value];
46 47
        }

48 49 50 51
        foreach ($this->getInvalidSessionValues() as $value) {
            $options[][] = ['session' => $value];
        }

52 53 54
        return $options;
    }
}