DeleteTest.php 1.78 KB
Newer Older
1 2 3 4
<?php

namespace MongoDB\Tests\Operation;

5
use MongoDB\Exception\InvalidArgumentException;
6
use MongoDB\Operation\Delete;
7
use function array_merge;
8 9 10 11

class DeleteTest extends TestCase
{
    /**
12
     * @dataProvider provideInvalidDocumentValues
13
     */
14
    public function testConstructorFilterArgumentTypeCheck($filter)
15
    {
16
        $this->expectException(InvalidArgumentException::class);
17 18 19 20
        new Delete($this->getDatabaseName(), $this->getCollectionName(), $filter, 0);
    }

    /**
21
     * @dataProvider provideInvalidLimitValues
22
     */
23
    public function testConstructorLimitArgumentMustBeOneOrZero($limit)
24
    {
25 26
        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessage('$limit must be 0 or 1');
Jeremy Mikola's avatar
Jeremy Mikola committed
27
        new Delete($this->getDatabaseName(), $this->getCollectionName(), [], $limit);
28 29 30 31
    }

    public function provideInvalidLimitValues()
    {
Jeremy Mikola's avatar
Jeremy Mikola committed
32
        return $this->wrapValuesForDataProvider(array_merge($this->getInvalidIntegerValues(), [-1, 2]));
33 34 35
    }

    /**
36
     * @dataProvider provideInvalidConstructorOptions
37
     */
38 39
    public function testConstructorOptionTypeChecks(array $options)
    {
40
        $this->expectException(InvalidArgumentException::class);
Jeremy Mikola's avatar
Jeremy Mikola committed
41
        new Delete($this->getDatabaseName(), $this->getCollectionName(), [], 1, $options);
42 43 44
    }

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

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

52 53 54 55
        foreach ($this->getInvalidSessionValues() as $value) {
            $options[][] = ['session' => $value];
        }

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

        return $options;
61 62
    }
}