|
2 | 2 |
|
3 | 3 | namespace MongoDB\Tests;
|
4 | 4 |
|
| 5 | +use MongoDB\Model\BSONDocument; |
5 | 6 | use MongoDB\Driver\ReadConcern;
|
6 | 7 | use MongoDB\Driver\WriteConcern;
|
7 | 8 |
|
8 | 9 | /**
|
9 | 10 | * Unit tests for utility functions.
|
10 | 11 | */
|
11 |
| -class FunctionsTest extends \PHPUnit_Framework_TestCase |
| 12 | +class FunctionsTest extends TestCase |
12 | 13 | {
|
| 14 | + /** |
| 15 | + * @dataProvider provideIndexSpecificationDocumentsAndGeneratedNames |
| 16 | + */ |
| 17 | + public function testGenerateIndexName($document, $expectedName) |
| 18 | + { |
| 19 | + $this->assertSame($expectedName, \MongoDB\generate_index_name($document)); |
| 20 | + } |
| 21 | + |
| 22 | + public function provideIndexSpecificationDocumentsAndGeneratedNames() |
| 23 | + { |
| 24 | + return [ |
| 25 | + [ ['x' => 1], 'x_1' ], |
| 26 | + [ ['x' => -1, 'y' => 1], 'x_-1_y_1' ], |
| 27 | + [ ['x' => '2dsphere', 'y' => 1 ], 'x_2dsphere_y_1' ], |
| 28 | + [ (object) ['x' => 1], 'x_1' ], |
| 29 | + [ new BSONDocument(['x' => 1]), 'x_1' ], |
| 30 | + ]; |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * @expectedException MongoDB\Exception\InvalidArgumentException |
| 35 | + * @dataProvider provideInvalidDocumentValues |
| 36 | + */ |
| 37 | + public function testGenerateIndexNameArgumentTypeCheck($document) |
| 38 | + { |
| 39 | + \MongoDB\generate_index_name($document); |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * @dataProvider provideIsFirstKeyOperatorDocuments |
| 44 | + */ |
| 45 | + public function testIsFirstKeyOperator($document, $isFirstKeyOperator) |
| 46 | + { |
| 47 | + $this->assertSame($isFirstKeyOperator, \MongoDB\is_first_key_operator($document)); |
| 48 | + } |
| 49 | + |
| 50 | + public function provideIsFirstKeyOperatorDocuments() |
| 51 | + { |
| 52 | + return [ |
| 53 | + [ ['y' => 1], false ], |
| 54 | + [ (object) ['y' => 1], false ], |
| 55 | + [ new BSONDocument(['y' => 1]), false ], |
| 56 | + [ ['$set' => ['y' => 1]], true ], |
| 57 | + [ (object) ['$set' => ['y' => 1]], true ], |
| 58 | + [ new BSONDocument(['$set' => ['y' => 1]]), true ], |
| 59 | + ]; |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * @expectedException MongoDB\Exception\InvalidArgumentException |
| 64 | + * @dataProvider provideInvalidDocumentValues |
| 65 | + */ |
| 66 | + public function testIsFirstKeyOperatorArgumentTypeCheck($document) |
| 67 | + { |
| 68 | + \MongoDB\is_first_key_operator($document); |
| 69 | + } |
| 70 | + |
13 | 71 | /**
|
14 | 72 | * @dataProvider provideReadConcernsAndDocuments
|
15 | 73 | */
|
|
0 commit comments