@@ -34,12 +34,12 @@ public function testGetCollection()
34
34
$ this ->connection ->expects ($ this ->once ())
35
35
->method ('selectDatabase ' )
36
36
->with ('test_antimattr_migrations ' )
37
- ->will ( $ this -> returnValue ( $ database) );
37
+ ->willReturn ( $ database );
38
38
39
39
$ database ->expects ($ this ->once ())
40
40
->method ('selectCollection ' )
41
41
->with ('antimattr_migration_versions_test ' )
42
- ->will ( $ this -> returnValue ( $ expectedCollection) );
42
+ ->willReturn ( $ expectedCollection );
43
43
44
44
$ collection = $ this ->configuration ->getCollection ();
45
45
$ this ->assertEquals ($ expectedCollection , $ collection );
@@ -58,12 +58,12 @@ public function testGetCurrentVersion()
58
58
$ this ->connection ->expects ($ this ->once ())
59
59
->method ('selectDatabase ' )
60
60
->with ('test_antimattr_migrations ' )
61
- ->will ( $ this -> returnValue ( $ database) );
61
+ ->willReturn ( $ database );
62
62
63
63
$ database ->expects ($ this ->once ())
64
64
->method ('selectCollection ' )
65
65
->with ('antimattr_migration_versions_test ' )
66
- ->will ( $ this -> returnValue ( $ collection) );
66
+ ->willReturn ( $ collection );
67
67
68
68
$ cursor = $ this ->buildMock ('Doctrine\MongoDB\Cursor ' );
69
69
@@ -72,21 +72,21 @@ public function testGetCurrentVersion()
72
72
$ collection ->expects ($ this ->once ())
73
73
->method ('find ' )
74
74
->with ($ in )
75
- ->will ( $ this -> returnValue ( $ cursor) );
75
+ ->willReturn ( $ cursor );
76
76
77
77
$ cursor ->expects ($ this ->once ())
78
78
->method ('sort ' )
79
79
->with (['v ' => -1 ])
80
- ->will ( $ this -> returnValue ( $ cursor) );
80
+ ->willReturn ( $ cursor );
81
81
82
82
$ cursor ->expects ($ this ->once ())
83
83
->method ('limit ' )
84
84
->with (1 )
85
- ->will ( $ this -> returnValue ( $ cursor) );
85
+ ->willReturn ( $ cursor );
86
86
87
87
$ cursor ->expects ($ this ->once ())
88
88
->method ('getNext ' )
89
- ->will ( $ this -> returnValue ( ['v ' => '20140822185743 ' ]) );
89
+ ->willReturn ( ['v ' => '20140822185743 ' ]);
90
90
91
91
$ version = $ this ->configuration ->getCurrentVersion ();
92
92
@@ -102,7 +102,7 @@ public function testGetDatabase()
102
102
$ this ->connection ->expects ($ this ->once ())
103
103
->method ('selectDatabase ' )
104
104
->with ('test_antimattr_migrations ' )
105
- ->will ( $ this -> returnValue ( $ expectedDatabase) );
105
+ ->willReturn ( $ expectedDatabase );
106
106
107
107
$ database = $ this ->configuration ->getDatabase ();
108
108
$ this ->assertEquals ($ expectedDatabase , $ database );
@@ -118,12 +118,12 @@ public function testGetMigratedVersions()
118
118
$ this ->connection ->expects ($ this ->once ())
119
119
->method ('selectDatabase ' )
120
120
->with ('test_antimattr_migrations ' )
121
- ->will ( $ this -> returnValue ( $ database) );
121
+ ->willReturn ( $ database );
122
122
123
123
$ database ->expects ($ this ->once ())
124
124
->method ('selectCollection ' )
125
125
->with ('antimattr_migration_versions_test ' )
126
- ->will ( $ this -> returnValue ( $ collection) );
126
+ ->willReturn ( $ collection );
127
127
128
128
$ foundVersions = [
129
129
['v ' => 'found1 ' ],
@@ -137,7 +137,7 @@ public function testGetMigratedVersions()
137
137
138
138
$ collection ->expects ($ this ->once ())
139
139
->method ('find ' )
140
- ->will ( $ this -> returnValue ( $ foundVersions) );
140
+ ->willReturn ( $ foundVersions );
141
141
142
142
$ versions = $ this ->configuration ->getMigratedVersions ();
143
143
$ this ->assertEquals ($ expectedVersions , $ versions );
@@ -153,22 +153,22 @@ public function testGetNumberOfExecutedMigrations()
153
153
$ this ->connection ->expects ($ this ->once ())
154
154
->method ('selectDatabase ' )
155
155
->with ('test_antimattr_migrations ' )
156
- ->will ( $ this -> returnValue ( $ database) );
156
+ ->willReturn ( $ database );
157
157
158
158
$ database ->expects ($ this ->once ())
159
159
->method ('selectCollection ' )
160
160
->with ('antimattr_migration_versions_test ' )
161
- ->will ( $ this -> returnValue ( $ collection) );
161
+ ->willReturn ( $ collection );
162
162
163
163
$ cursor = $ this ->buildMock ('Doctrine\MongoDB\Cursor ' );
164
164
165
165
$ collection ->expects ($ this ->once ())
166
166
->method ('find ' )
167
- ->will ( $ this -> returnValue ( $ cursor) );
167
+ ->willReturn ( $ cursor );
168
168
169
169
$ cursor ->expects ($ this ->once ())
170
170
->method ('count ' )
171
- ->will ( $ this -> returnValue ( 2 ) );
171
+ ->willReturn ( 2 );
172
172
173
173
$ this ->assertEquals (2 , $ this ->configuration ->getNumberOfExecutedMigrations ());
174
174
}
@@ -211,32 +211,30 @@ public function testHasVersionMigrated()
211
211
$ this ->connection ->expects ($ this ->once ())
212
212
->method ('selectDatabase ' )
213
213
->with ('test_antimattr_migrations ' )
214
- ->will ( $ this -> returnValue ( $ database) );
214
+ ->willReturn ( $ database );
215
215
216
216
$ database ->expects ($ this ->once ())
217
217
->method ('selectCollection ' )
218
218
->with ('antimattr_migration_versions_test ' )
219
- ->will ( $ this -> returnValue ( $ collection) );
219
+ ->willReturn ( $ collection );
220
220
221
221
$ version1 ->expects ($ this ->once ())
222
222
->method ('getVersion ' )
223
- ->will ( $ this -> returnValue ( 'found ' ) );
223
+ ->willReturn ( 'found ' );
224
224
225
225
$ version2 ->expects ($ this ->once ())
226
226
->method ('getVersion ' )
227
- ->will ($ this ->returnValue ('found2 ' ));
228
-
229
- $ cursor = $ this ->buildMock ('MongoCursor ' );
227
+ ->willReturn ('found2 ' );
230
228
231
229
$ collection ->expects ($ this ->at (1 ))
232
230
->method ('findOne ' )
233
231
->with (['v ' => 'found ' ])
234
- ->will ( $ this -> returnValue ( 'foo ' ) );
232
+ ->willReturn ( 'foo ' );
235
233
236
234
$ collection ->expects ($ this ->at (2 ))
237
235
->method ('findOne ' )
238
236
->with (['v ' => 'found2 ' ])
239
- ->will ( $ this -> returnValue ( null ) );
237
+ ->willReturn ( null );
240
238
241
239
$ this ->assertTrue ($ this ->configuration ->hasVersionMigrated ($ version1 ));
242
240
$ this ->assertFalse ($ this ->configuration ->hasVersionMigrated ($ version2 ));
@@ -258,10 +256,10 @@ public function testGetUnavailableMigratedVersions()
258
256
->getMock ();
259
257
$ configuration ->expects ($ this ->once ())
260
258
->method ('getMigratedVersions ' )
261
- ->will ( $ this -> returnValue ( ['1 ' , '2 ' ]) );
259
+ ->willReturn ( ['1 ' , '2 ' ]);
262
260
$ configuration ->expects ($ this ->once ())
263
261
->method ('getAvailableVersions ' )
264
- ->will ( $ this -> returnValue ( ['2 ' , '3 ' ]) );
262
+ ->willReturn ( ['2 ' , '3 ' ]);
265
263
266
264
$ this ->assertEquals (['1 ' ], $ configuration ->getUnavailableMigratedVersions ());
267
265
}
@@ -272,6 +270,74 @@ public function testValidate()
272
270
self ::assertNull ($ this ->configuration ->validate ());
273
271
}
274
272
273
+ /**
274
+ * @expectedException \DomainException
275
+ * @expectedExceptionMessage Unexpected duplicate version records in the database
276
+ */
277
+ public function testDuplicateInGetMigratedTimestampThrowsException ()
278
+ {
279
+ $ this ->prepareValidConfiguration ();
280
+
281
+ $ collection = $ this ->buildMock ('Doctrine\MongoDB\Collection ' );
282
+ $ database = $ this ->buildMock ('Doctrine\MongoDB\Database ' );
283
+
284
+ $ this ->connection ->expects ($ this ->once ())
285
+ ->method ('selectDatabase ' )
286
+ ->with ('test_antimattr_migrations ' )
287
+ ->willReturn ($ database );
288
+
289
+ $ database ->expects ($ this ->once ())
290
+ ->method ('selectCollection ' )
291
+ ->with ('antimattr_migration_versions_test ' )
292
+ ->willReturn ($ collection );
293
+
294
+ $ cursor = $ this ->buildMock ('Doctrine\MongoDB\Cursor ' );
295
+
296
+ $ collection ->expects ($ this ->once ())
297
+ ->method ('find ' )
298
+ ->willReturn ($ cursor );
299
+
300
+ $ cursor ->expects ($ this ->exactly (2 ))
301
+ ->method ('count ' )
302
+ ->willReturn (2 );
303
+
304
+ $ this ->configuration ->getMigratedTimestamp ('1 ' );
305
+ }
306
+
307
+ public function testGetMigratedTimestamp ()
308
+ {
309
+ $ this ->prepareValidConfiguration ();
310
+
311
+ $ collection = $ this ->buildMock ('Doctrine\MongoDB\Collection ' );
312
+ $ database = $ this ->buildMock ('Doctrine\MongoDB\Database ' );
313
+
314
+ $ this ->connection ->expects ($ this ->once ())
315
+ ->method ('selectDatabase ' )
316
+ ->with ('test_antimattr_migrations ' )
317
+ ->willReturn ($ database );
318
+
319
+ $ database ->expects ($ this ->once ())
320
+ ->method ('selectCollection ' )
321
+ ->with ('antimattr_migration_versions_test ' )
322
+ ->willReturn ($ collection );
323
+
324
+ $ cursor = $ this ->buildMock ('Doctrine\MongoDB\Cursor ' );
325
+
326
+ $ collection ->expects ($ this ->once ())
327
+ ->method ('find ' )
328
+ ->willReturn ($ cursor );
329
+
330
+ $ cursor ->expects ($ this ->exactly (2 ))
331
+ ->method ('count ' )
332
+ ->willReturn (1 );
333
+
334
+ $ cursor ->expects ($ this ->once ())
335
+ ->method ('getNext ' )
336
+ ->willReturn (['t ' => new \DateTime ()]);
337
+
338
+ $ this ->assertTrue (is_numeric ($ this ->configuration ->getMigratedTimestamp ('1 ' )));
339
+ }
340
+
275
341
private function prepareValidConfiguration ()
276
342
{
277
343
$ directory = dirname (__DIR__ ) . '/Resources/Migrations/ ' ;
0 commit comments