summaryrefslogtreecommitdiffstats
path: root/167.patch
blob: 846b811901d635316adf9dc33b8b08c9b620883d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
From 0cf254b9a28ccf8aa9e0e18f802b63d58f3e5e92 Mon Sep 17 00:00:00 2001
From: Emir Beganovic <beganovic.emir@gmail.com>
Date: Tue, 11 Apr 2017 20:53:00 +0200
Subject: [PATCH 1/2] Check different behaviour for index version for MongoDB
 3.4

---
 .travis.yml                                        | 134 ++++++++++++++++++---
 .../MongoDbAdapter/Mongo/MongoCollectionTest.php   |  22 ++--
 tests/Alcaeus/MongoDbAdapter/Mongo/TestCase.php    |   0
 tests/Alcaeus/MongoDbAdapter/TestCase.php          |  11 ++
 4 files changed, 139 insertions(+), 28 deletions(-)
 create mode 100644 tests/Alcaeus/MongoDbAdapter/Mongo/TestCase.php

diff --git a/tests/Alcaeus/MongoDbAdapter/Mongo/MongoCollectionTest.php b/tests/Alcaeus/MongoDbAdapter/Mongo/MongoCollectionTest.php
index 52a163f..b1f1ede 100644
--- a/tests/Alcaeus/MongoDbAdapter/Mongo/MongoCollectionTest.php
+++ b/tests/Alcaeus/MongoDbAdapter/Mongo/MongoCollectionTest.php
@@ -1301,12 +1301,14 @@ public function testDeleteIndexesForNonExistingCollection()
         $this->assertSame($expected, $this->getcollection('nonExisting')->deleteIndexes());
     }
 
-    public static function dataGetIndexInfo()
+    public function dataGetIndexInfo()
     {
+    	$indexVersion = $this->getDefaultIndexVersion();
+
         return [
             'plainIndex' => [
                 'expectedIndex' => [
-                    'v' => 1,
+                    'v' => $indexVersion,
                     'key' => ['foo' => 1],
                     'name' => 'foo_1',
                     'ns' => 'mongo-php-adapter.test',
@@ -1316,7 +1318,7 @@ public static function dataGetIndexInfo()
             ],
             'uniqueIndex' => [
                 'expectedIndex' => [
-                    'v' => 1,
+                    'v' => $indexVersion,
                     'key' => ['foo' => 1],
                     'name' => 'foo_1',
                     'ns' => 'mongo-php-adapter.test',
@@ -1327,7 +1329,7 @@ public static function dataGetIndexInfo()
             ],
             'sparseIndex' => [
                 'expectedIndex' => [
-                    'v' => 1,
+                    'v' => $indexVersion,
                     'key' => ['foo' => 1],
                     'name' => 'foo_1',
                     'ns' => 'mongo-php-adapter.test',
@@ -1338,7 +1340,7 @@ public static function dataGetIndexInfo()
             ],
             'ttlIndex' => [
                 'expectedIndex' => [
-                    'v' => 1,
+                    'v' => $indexVersion,
                     'key' => ['foo' => 1],
                     'name' => 'foo_1',
                     'ns' => 'mongo-php-adapter.test',
@@ -1349,7 +1351,7 @@ public static function dataGetIndexInfo()
             ],
             'textIndex' => [
                 'expectedIndex' => [
-                    'v' => 1,
+                    'v' => $indexVersion,
                     'key' => [
                         '_fts' => 'text',
                         '_ftsx' => 1,
@@ -1368,7 +1370,7 @@ public static function dataGetIndexInfo()
             ],
             'partialFilterExpression' => [
                 'expectedIndex' => [
-                    'v' => 1,
+                    'v' => $indexVersion,
                     'key' => ['foo' => 1],
                     'name' => 'foo_1',
                     'ns' => 'mongo-php-adapter.test',
@@ -1383,7 +1385,7 @@ public static function dataGetIndexInfo()
             ],
             'geoSpatial' => [
                 'expectedIndex' => [
-                    'v' => 1,
+                    'v' => $indexVersion,
                     'key' => ['foo' => '2dsphere'],
                     'name' => 'foo_2dsphere',
                     'ns' => 'mongo-php-adapter.test',
@@ -1394,7 +1396,7 @@ public static function dataGetIndexInfo()
             ],
             'geoHaystack' => [
                 'expectedIndex' => [
-                    'v' => 1,
+                    'v' => $indexVersion,
                     'key' => ['foo' => 'geoHaystack', 'bar' => 1],
                     'name' => 'foo_geoHaystack_bar_1',
                     'ns' => 'mongo-php-adapter.test',
@@ -1412,7 +1414,7 @@ public static function dataGetIndexInfo()
     public function testGetIndexInfo($expectedIndex, $fields, $options)
     {
         $idIndex = [
-            'v' => 1,
+            'v' => $this->getDefaultIndexVersion(),
             'key' => ['_id' => 1],
             'name' => '_id_',
             'ns' => 'mongo-php-adapter.test',
diff --git a/tests/Alcaeus/MongoDbAdapter/Mongo/TestCase.php b/tests/Alcaeus/MongoDbAdapter/Mongo/TestCase.php
new file mode 100644
index 0000000..e69de29
diff --git a/tests/Alcaeus/MongoDbAdapter/TestCase.php b/tests/Alcaeus/MongoDbAdapter/TestCase.php
index 6964357..3dd96d6 100644
--- a/tests/Alcaeus/MongoDbAdapter/TestCase.php
+++ b/tests/Alcaeus/MongoDbAdapter/TestCase.php
@@ -163,4 +163,15 @@ protected function skipTestIf($condition)
             $this->markTestSkipped('Test only applies when running against mongo-php-adapter');
         }
     }
+
+    /**
+     * Indexes created in MongoDB 3.4 default to v: 2.
+     * @return int
+     * @see https://docs.mongodb.com/manual/release-notes/3.4-compatibility/#backwards-incompatible-features
+     */
+    protected function getDefaultIndexVersion()
+    {
+        $serverInfo = $this->getDatabase()->command(array('buildinfo' => true));
+        return isset($serverInfo['version']) && version_compare($serverInfo['version'], '3.4.0', '>=') ? 2 : 1;
+    }
 }

From 425d996ec86c5e5c93ae61bb1d0caf26cf06bda4 Mon Sep 17 00:00:00 2001
From: Emir Beganovic <beganovic.emir@gmail.com>
Date: Wed, 12 Apr 2017 01:51:41 +0200
Subject: [PATCH 2/2] One-liner

---
 .travis.yml | 1 -
 1 file changed, 1 deletion(-)