1
1
<?php
2
2
3
- namespace MongoDB \Tests \SpecTests ;
3
+ namespace MongoDB \Tests \UnifiedSpecTests \ Constraint ;
4
4
5
5
use MongoDB \BSON \Binary ;
6
6
use MongoDB \BSON \Decimal128 ;
20
20
use function unserialize ;
21
21
use const PHP_INT_SIZE ;
22
22
23
- class DocumentsMatchConstraintTest extends TestCase
23
+ class DocumentsMatchTest extends TestCase
24
24
{
25
25
public function testIgnoreExtraKeysInRoot ()
26
26
{
27
- $ c = new DocumentsMatchConstraint (['x ' => 1 , 'y ' => ['a ' => 1 , 'b ' => 2 ]], true , false );
27
+ $ c = new DocumentsMatch (['x ' => 1 , 'y ' => ['a ' => 1 , 'b ' => 2 ]], true , false );
28
28
29
29
$ this ->assertResult (false , $ c , ['x ' => 1 , 'y ' => 2 ], 'Incorrect value ' );
30
30
$ this ->assertResult (true , $ c , ['x ' => 1 , 'y ' => ['a ' => 1 , 'b ' => 2 ]], 'Exact match ' );
@@ -33,7 +33,7 @@ public function testIgnoreExtraKeysInRoot()
33
33
$ this ->assertResult (true , $ c , ['y ' => ['b ' => 2 , 'a ' => 1 ], 'x ' => 1 ], 'Root and embedded key order is not significant ' );
34
34
35
35
// Arrays are always interpreted as root documents
36
- $ c = new DocumentsMatchConstraint ([1 , ['a ' => 1 ]], true , false );
36
+ $ c = new DocumentsMatch ([1 , ['a ' => 1 ]], true , false );
37
37
38
38
$ this ->assertResult (false , $ c , [1 , 2 ], 'Incorrect value ' );
39
39
$ this ->assertResult (true , $ c , [1 , ['a ' => 1 ]], 'Exact match ' );
@@ -43,7 +43,7 @@ public function testIgnoreExtraKeysInRoot()
43
43
44
44
public function testIgnoreExtraKeysInEmbedded ()
45
45
{
46
- $ c = new DocumentsMatchConstraint (['x ' => 1 , 'y ' => ['a ' => 1 , 'b ' => 2 ]], false , true );
46
+ $ c = new DocumentsMatch (['x ' => 1 , 'y ' => ['a ' => 1 , 'b ' => 2 ]], false , true );
47
47
48
48
$ this ->assertResult (false , $ c , ['x ' => 1 , 'y ' => 2 ], 'Incorrect value ' );
49
49
$ this ->assertResult (false , $ c , ['x ' => 1 , 'y ' => ['a ' => 1 , 'b ' => 3 ]], 'Incorrect value ' );
@@ -53,7 +53,7 @@ public function testIgnoreExtraKeysInEmbedded()
53
53
$ this ->assertResult (true , $ c , ['y ' => ['b ' => 2 , 'a ' => 1 ], 'x ' => 1 ], 'Root and embedded Key order is not significant ' );
54
54
55
55
// Arrays are always interpreted as root documents
56
- $ c = new DocumentsMatchConstraint ([1 , ['a ' => 1 ]], false , true );
56
+ $ c = new DocumentsMatch ([1 , ['a ' => 1 ]], false , true );
57
57
58
58
$ this ->assertResult (false , $ c , [1 , 2 ], 'Incorrect value ' );
59
59
$ this ->assertResult (true , $ c , [1 , ['a ' => 1 ]], 'Exact match ' );
@@ -64,7 +64,7 @@ public function testIgnoreExtraKeysInEmbedded()
64
64
65
65
public function testPlaceholders ()
66
66
{
67
- $ c = new DocumentsMatchConstraint (['x ' => '42 ' , 'y ' => 42 , 'z ' => ['a ' => 24 ]], false , false , [24 , 42 ]);
67
+ $ c = new DocumentsMatch (['x ' => '42 ' , 'y ' => 42 , 'z ' => ['a ' => 24 ]], false , false , [24 , 42 ]);
68
68
69
69
$ this ->assertResult (true , $ c , ['x ' => '42 ' , 'y ' => 'foo ' , 'z ' => ['a ' => 1 ]], 'Placeholders accept any value ' );
70
70
$ this ->assertResult (false , $ c , ['x ' => 42 , 'y ' => 'foo ' , 'z ' => ['a ' => 1 ]], 'Placeholder type must match ' );
@@ -76,7 +76,7 @@ public function testPlaceholders()
76
76
*/
77
77
public function testBSONTypeAssertions ($ type , $ value )
78
78
{
79
- $ constraint = new DocumentsMatchConstraint (['x ' => ['$$type ' => $ type ]]);
79
+ $ constraint = new DocumentsMatch (['x ' => ['$$type ' => $ type ]]);
80
80
81
81
$ this ->assertResult (true , $ constraint , ['x ' => $ value ], 'Type matches ' );
82
82
}
@@ -114,7 +114,7 @@ public function provideBSONTypes()
114
114
/**
115
115
* @dataProvider errorMessageProvider
116
116
*/
117
- public function testErrorMessages ($ expectedMessagePart , DocumentsMatchConstraint $ constraint , $ actualValue )
117
+ public function testErrorMessages ($ expectedMessagePart , DocumentsMatch $ constraint , $ actualValue )
118
118
{
119
119
try {
120
120
$ constraint ->evaluate ($ actualValue );
@@ -130,38 +130,38 @@ public function errorMessageProvider()
130
130
return [
131
131
'Root type mismatch ' => [
132
132
'MongoDB\Model\BSONArray Object (...) is not instance of expected class "MongoDB\Model\BSONDocument" ' ,
133
- new DocumentsMatchConstraint (['foo ' => 'bar ' ]),
133
+ new DocumentsMatch (['foo ' => 'bar ' ]),
134
134
new BSONArray (['foo ' => 'bar ' ]),
135
135
],
136
136
'Missing key ' => [
137
137
'$actual is missing key: "foo.bar" ' ,
138
- new DocumentsMatchConstraint (['foo ' => ['bar ' => 'baz ' ]]),
138
+ new DocumentsMatch (['foo ' => ['bar ' => 'baz ' ]]),
139
139
['foo ' => ['foo ' => 'bar ' ]],
140
140
],
141
141
'Extra key ' => [
142
142
'$actual has extra key: "foo.foo" ' ,
143
- new DocumentsMatchConstraint (['foo ' => ['bar ' => 'baz ' ]]),
143
+ new DocumentsMatch (['foo ' => ['bar ' => 'baz ' ]]),
144
144
['foo ' => ['foo ' => 'bar ' , 'bar ' => 'baz ' ]],
145
145
],
146
146
'Scalar value not equal ' => [
147
147
'Field path "foo": Failed asserting that two values are equal. ' ,
148
- new DocumentsMatchConstraint (['foo ' => 'bar ' ]),
148
+ new DocumentsMatch (['foo ' => 'bar ' ]),
149
149
['foo ' => 'baz ' ],
150
150
],
151
151
'Scalar type mismatch ' => [
152
152
'Field path "foo": Failed asserting that two values are equal. ' ,
153
- new DocumentsMatchConstraint (['foo ' => 42 ]),
153
+ new DocumentsMatch (['foo ' => 42 ]),
154
154
['foo ' => '42 ' ],
155
155
],
156
156
'Type mismatch ' => [
157
157
'Field path "foo": MongoDB\Model\BSONDocument Object (...) is not instance of expected type "MongoDB\Model\BSONArray". ' ,
158
- new DocumentsMatchConstraint (['foo ' => ['bar ' ]]),
158
+ new DocumentsMatch (['foo ' => ['bar ' ]]),
159
159
['foo ' => (object ) ['bar ' ]],
160
160
],
161
161
];
162
162
}
163
163
164
- private function assertResult ($ expectedResult , DocumentsMatchConstraint $ constraint , $ value , $ message )
164
+ private function assertResult ($ expectedResult , DocumentsMatch $ constraint , $ value , $ message )
165
165
{
166
166
$ this ->assertSame ($ expectedResult , $ constraint ->evaluate ($ value , '' , true ), $ message );
167
167
}
0 commit comments