@@ -1222,36 +1222,130 @@ public function testDeleteIndexesForNonExistingCollection()
1222
1222
$ this ->assertSame ($ expected , $ this ->getcollection ('nonExisting ' )->deleteIndexes ());
1223
1223
}
1224
1224
1225
- public function testGetIndexInfo ()
1225
+ public static function dataGetIndexInfo ()
1226
1226
{
1227
- $ collection = $ this -> getCollection ();
1228
- $ collection -> createIndex ([ ' foo ' => 1 ]);
1229
- $ collection -> createIndex ([ ' bar ' => 1 ], [ ' unique ' => true ]);
1230
-
1231
- $ expected = [
1232
- [
1233
- ' v ' => 1 ,
1234
- ' key ' => [ ' _id ' => 1 ],
1235
- 'name ' => ' _id_ ' ,
1236
- 'ns ' => ' mongo-php-adapter.test ' ,
1227
+ return [
1228
+ ' plainIndex ' => [
1229
+ ' expectedIndex ' => [
1230
+ ' v ' => 1 ,
1231
+ ' key ' => [ ' foo ' => 1 ],
1232
+ ' name ' => ' foo_1 ' ,
1233
+ ' ns ' => ' mongo-php-adapter.test ' ,
1234
+ ],
1235
+ 'fields ' => [ ' foo ' => 1 ] ,
1236
+ 'options ' => [] ,
1237
1237
],
1238
- [
1239
- 'v ' => 1 ,
1240
- 'key ' => ['foo ' => 1 ],
1241
- 'name ' => 'foo_1 ' ,
1242
- 'ns ' => 'mongo-php-adapter.test ' ,
1238
+ 'uniqueIndex ' => [
1239
+ 'expectedIndex ' => [
1240
+ 'v ' => 1 ,
1241
+ 'key ' => ['foo ' => 1 ],
1242
+ 'name ' => 'foo_1 ' ,
1243
+ 'ns ' => 'mongo-php-adapter.test ' ,
1244
+ 'unique ' => true ,
1245
+ ],
1246
+ 'fields ' => ['foo ' => 1 ],
1247
+ 'options ' => ['unique ' => true ],
1243
1248
],
1244
- [
1245
- 'v ' => 1 ,
1246
- 'key ' => ['bar ' => 1 ],
1247
- 'name ' => 'bar_1 ' ,
1248
- 'ns ' => 'mongo-php-adapter.test ' ,
1249
- 'unique ' => true ,
1249
+ 'sparseIndex ' => [
1250
+ 'expectedIndex ' => [
1251
+ 'v ' => 1 ,
1252
+ 'key ' => ['foo ' => 1 ],
1253
+ 'name ' => 'foo_1 ' ,
1254
+ 'ns ' => 'mongo-php-adapter.test ' ,
1255
+ 'sparse ' => true ,
1256
+ ],
1257
+ 'fields ' => ['foo ' => 1 ],
1258
+ 'options ' => ['sparse ' => true ],
1259
+ ],
1260
+ 'ttlIndex ' => [
1261
+ 'expectedIndex ' => [
1262
+ 'v ' => 1 ,
1263
+ 'key ' => ['foo ' => 1 ],
1264
+ 'name ' => 'foo_1 ' ,
1265
+ 'ns ' => 'mongo-php-adapter.test ' ,
1266
+ 'expireAfterSeconds ' => 86400 ,
1267
+ ],
1268
+ 'fields ' => ['foo ' => 1 ],
1269
+ 'options ' => ['expireAfterSeconds ' => 86400 ],
1270
+ ],
1271
+ 'textIndex ' => [
1272
+ 'expectedIndex ' => [
1273
+ 'v ' => 1 ,
1274
+ 'key ' => [
1275
+ '_fts ' => 'text ' ,
1276
+ '_ftsx ' => 1 ,
1277
+ ],
1278
+ 'name ' => 'foo_text ' ,
1279
+ 'ns ' => 'mongo-php-adapter.test ' ,
1280
+ 'weights ' => [
1281
+ 'foo ' => 1 ,
1282
+ ],
1283
+ 'default_language ' => 'english ' ,
1284
+ 'language_override ' => 'language ' ,
1285
+ 'textIndexVersion ' => 3 ,
1286
+ ],
1287
+ 'fields ' => ['foo ' => 'text ' ],
1288
+ 'options ' => [],
1289
+ ],
1290
+ 'partialFilterExpression ' => [
1291
+ 'expectedIndex ' => [
1292
+ 'v ' => 1 ,
1293
+ 'key ' => ['foo ' => 1 ],
1294
+ 'name ' => 'foo_1 ' ,
1295
+ 'ns ' => 'mongo-php-adapter.test ' ,
1296
+ 'partialFilterExpression ' => [
1297
+ 'bar ' => ['$gt ' => 1 ],
1298
+ ],
1299
+ ],
1300
+ 'fields ' => ['foo ' => 1 ],
1301
+ 'options ' => [
1302
+ 'partialFilterExpression ' => ['bar ' => ['$gt ' => 1 ]],
1303
+ ],
1304
+ ],
1305
+ 'geoSpatial ' => [
1306
+ 'expectedIndex ' => [
1307
+ 'v ' => 1 ,
1308
+ 'key ' => ['foo ' => '2dsphere ' ],
1309
+ 'name ' => 'foo_2dsphere ' ,
1310
+ 'ns ' => 'mongo-php-adapter.test ' ,
1311
+ '2dsphereIndexVersion ' => 3 ,
1312
+ ],
1313
+ 'fields ' => ['foo ' => '2dsphere ' ],
1314
+ 'options ' => [],
1315
+ ],
1316
+ 'geoHaystack ' => [
1317
+ 'expectedIndex ' => [
1318
+ 'v ' => 1 ,
1319
+ 'key ' => ['foo ' => 'geoHaystack ' , 'bar ' => 1 ],
1320
+ 'name ' => 'foo_geoHaystack_bar_1 ' ,
1321
+ 'ns ' => 'mongo-php-adapter.test ' ,
1322
+ 'bucketSize ' => 10 ,
1323
+ ],
1324
+ 'fields ' => ['foo ' => 'geoHaystack ' , 'bar ' => 1 ],
1325
+ 'options ' => ['bucketSize ' => 10 ],
1250
1326
],
1251
1327
];
1328
+ }
1329
+
1330
+ /**
1331
+ * @dataProvider dataGetIndexInfo
1332
+ */
1333
+ public function testGetIndexInfo ($ expectedIndex , $ fields , $ options )
1334
+ {
1335
+ $ idIndex = [
1336
+ 'v ' => 1 ,
1337
+ 'key ' => ['_id ' => 1 ],
1338
+ 'name ' => '_id_ ' ,
1339
+ 'ns ' => 'mongo-php-adapter.test ' ,
1340
+ ];
1341
+
1342
+ $ expectedIndexInfo = [$ idIndex , $ expectedIndex ];
1343
+
1344
+ $ collection = $ this ->getCollection ();
1345
+ $ collection ->createIndex ($ fields , $ options );
1252
1346
1253
1347
$ this ->assertEquals (
1254
- $ expected ,
1348
+ $ expectedIndexInfo ,
1255
1349
$ collection ->getIndexInfo ()
1256
1350
);
1257
1351
}
0 commit comments