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

namespace MongoDB\Tests\Operation;

use MongoDB\Operation\Delete;

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

    /**
     * @expectedException MongoDB\Exception\InvalidArgumentException
20 21
     * @expectedExceptionMessage $limit must be 0 or 1
     * @dataProvider provideInvalidLimitValues
22
     */
23
    public function testConstructorLimitArgumentMustBeOneOrZero($limit)
24
    {
Jeremy Mikola's avatar
Jeremy Mikola committed
25
        new Delete($this->getDatabaseName(), $this->getCollectionName(), [], $limit);
26 27 28 29
    }

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

    /**
34
     * @expectedException MongoDB\Exception\InvalidArgumentException
35
     * @dataProvider provideInvalidConstructorOptions
36
     */
37 38
    public function testConstructorOptionTypeChecks(array $options)
    {
Jeremy Mikola's avatar
Jeremy Mikola committed
39
        new Delete($this->getDatabaseName(), $this->getCollectionName(), [], 1, $options);
40 41 42
    }

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

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

50
        foreach ($this->getInvalidWriteConcernValues() as $value) {
Jeremy Mikola's avatar
Jeremy Mikola committed
51
            $options[][] = ['writeConcern' => $value];
52 53 54
        }

        return $options;
55 56
    }
}