CountTest.php 1.64 KB
Newer Older
1 2 3 4 5 6 7 8 9
<?php

namespace MongoDB\Tests\Operation;

use MongoDB\Operation\Count;

class CountTest extends TestCase
{
    /**
10
     * @expectedException MongoDB\Exception\InvalidArgumentException
11 12 13 14 15 16 17 18
     * @dataProvider provideInvalidDocumentValues
     */
    public function testConstructorFilterArgumentTypeCheck($filter)
    {
        new Count($this->getDatabaseName(), $this->getCollectionName(), $filter);
    }

    /**
19
     * @expectedException MongoDB\Exception\InvalidArgumentException
20 21 22 23
     * @dataProvider provideInvalidConstructorOptions
     */
    public function testConstructorOptionTypeChecks(array $options)
    {
Jeremy Mikola's avatar
Jeremy Mikola committed
24
        new Count($this->getDatabaseName(), $this->getCollectionName(), [], $options);
25 26 27 28
    }

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

        foreach ($this->getInvalidHintValues() as $value) {
Jeremy Mikola's avatar
Jeremy Mikola committed
32
            $options[][] = ['hint' => $value];
33 34 35
        }

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

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

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

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

51
        foreach ($this->getInvalidIntegerValues() as $value) {
Jeremy Mikola's avatar
Jeremy Mikola committed
52
            $options[][] = ['skip' => $value];
53 54 55 56 57 58 59
        }

        return $options;
    }

    private function getInvalidHintValues()
    {
Jeremy Mikola's avatar
Jeremy Mikola committed
60
        return [123, 3.14, true];
61 62
    }
}