@@ -34,12 +34,12 @@ public function testGetCollection()
3434 $ this ->connection ->expects ($ this ->once ())
3535 ->method ('selectDatabase ' )
3636 ->with ('test_antimattr_migrations ' )
37- ->will ( $ this -> returnValue ( $ database) );
37+ ->willReturn ( $ database );
3838
3939 $ database ->expects ($ this ->once ())
4040 ->method ('selectCollection ' )
4141 ->with ('antimattr_migration_versions_test ' )
42- ->will ( $ this -> returnValue ( $ expectedCollection) );
42+ ->willReturn ( $ expectedCollection );
4343
4444 $ collection = $ this ->configuration ->getCollection ();
4545 $ this ->assertEquals ($ expectedCollection , $ collection );
@@ -58,12 +58,12 @@ public function testGetCurrentVersion()
5858 $ this ->connection ->expects ($ this ->once ())
5959 ->method ('selectDatabase ' )
6060 ->with ('test_antimattr_migrations ' )
61- ->will ( $ this -> returnValue ( $ database) );
61+ ->willReturn ( $ database );
6262
6363 $ database ->expects ($ this ->once ())
6464 ->method ('selectCollection ' )
6565 ->with ('antimattr_migration_versions_test ' )
66- ->will ( $ this -> returnValue ( $ collection) );
66+ ->willReturn ( $ collection );
6767
6868 $ cursor = $ this ->buildMock ('Doctrine\MongoDB\Cursor ' );
6969
@@ -72,21 +72,21 @@ public function testGetCurrentVersion()
7272 $ collection ->expects ($ this ->once ())
7373 ->method ('find ' )
7474 ->with ($ in )
75- ->will ( $ this -> returnValue ( $ cursor) );
75+ ->willReturn ( $ cursor );
7676
7777 $ cursor ->expects ($ this ->once ())
7878 ->method ('sort ' )
7979 ->with (['v ' => -1 ])
80- ->will ( $ this -> returnValue ( $ cursor) );
80+ ->willReturn ( $ cursor );
8181
8282 $ cursor ->expects ($ this ->once ())
8383 ->method ('limit ' )
8484 ->with (1 )
85- ->will ( $ this -> returnValue ( $ cursor) );
85+ ->willReturn ( $ cursor );
8686
8787 $ cursor ->expects ($ this ->once ())
8888 ->method ('getNext ' )
89- ->will ( $ this -> returnValue ( ['v ' => '20140822185743 ' ]) );
89+ ->willReturn ( ['v ' => '20140822185743 ' ]);
9090
9191 $ version = $ this ->configuration ->getCurrentVersion ();
9292
@@ -102,7 +102,7 @@ public function testGetDatabase()
102102 $ this ->connection ->expects ($ this ->once ())
103103 ->method ('selectDatabase ' )
104104 ->with ('test_antimattr_migrations ' )
105- ->will ( $ this -> returnValue ( $ expectedDatabase) );
105+ ->willReturn ( $ expectedDatabase );
106106
107107 $ database = $ this ->configuration ->getDatabase ();
108108 $ this ->assertEquals ($ expectedDatabase , $ database );
@@ -118,12 +118,12 @@ public function testGetMigratedVersions()
118118 $ this ->connection ->expects ($ this ->once ())
119119 ->method ('selectDatabase ' )
120120 ->with ('test_antimattr_migrations ' )
121- ->will ( $ this -> returnValue ( $ database) );
121+ ->willReturn ( $ database );
122122
123123 $ database ->expects ($ this ->once ())
124124 ->method ('selectCollection ' )
125125 ->with ('antimattr_migration_versions_test ' )
126- ->will ( $ this -> returnValue ( $ collection) );
126+ ->willReturn ( $ collection );
127127
128128 $ foundVersions = [
129129 ['v ' => 'found1 ' ],
@@ -137,7 +137,7 @@ public function testGetMigratedVersions()
137137
138138 $ collection ->expects ($ this ->once ())
139139 ->method ('find ' )
140- ->will ( $ this -> returnValue ( $ foundVersions) );
140+ ->willReturn ( $ foundVersions );
141141
142142 $ versions = $ this ->configuration ->getMigratedVersions ();
143143 $ this ->assertEquals ($ expectedVersions , $ versions );
@@ -153,22 +153,22 @@ public function testGetNumberOfExecutedMigrations()
153153 $ this ->connection ->expects ($ this ->once ())
154154 ->method ('selectDatabase ' )
155155 ->with ('test_antimattr_migrations ' )
156- ->will ( $ this -> returnValue ( $ database) );
156+ ->willReturn ( $ database );
157157
158158 $ database ->expects ($ this ->once ())
159159 ->method ('selectCollection ' )
160160 ->with ('antimattr_migration_versions_test ' )
161- ->will ( $ this -> returnValue ( $ collection) );
161+ ->willReturn ( $ collection );
162162
163163 $ cursor = $ this ->buildMock ('Doctrine\MongoDB\Cursor ' );
164164
165165 $ collection ->expects ($ this ->once ())
166166 ->method ('find ' )
167- ->will ( $ this -> returnValue ( $ cursor) );
167+ ->willReturn ( $ cursor );
168168
169169 $ cursor ->expects ($ this ->once ())
170170 ->method ('count ' )
171- ->will ( $ this -> returnValue ( 2 ) );
171+ ->willReturn ( 2 );
172172
173173 $ this ->assertEquals (2 , $ this ->configuration ->getNumberOfExecutedMigrations ());
174174 }
@@ -211,32 +211,30 @@ public function testHasVersionMigrated()
211211 $ this ->connection ->expects ($ this ->once ())
212212 ->method ('selectDatabase ' )
213213 ->with ('test_antimattr_migrations ' )
214- ->will ( $ this -> returnValue ( $ database) );
214+ ->willReturn ( $ database );
215215
216216 $ database ->expects ($ this ->once ())
217217 ->method ('selectCollection ' )
218218 ->with ('antimattr_migration_versions_test ' )
219- ->will ( $ this -> returnValue ( $ collection) );
219+ ->willReturn ( $ collection );
220220
221221 $ version1 ->expects ($ this ->once ())
222222 ->method ('getVersion ' )
223- ->will ( $ this -> returnValue ( 'found ' ) );
223+ ->willReturn ( 'found ' );
224224
225225 $ version2 ->expects ($ this ->once ())
226226 ->method ('getVersion ' )
227- ->will ($ this ->returnValue ('found2 ' ));
228-
229- $ cursor = $ this ->buildMock ('MongoCursor ' );
227+ ->willReturn ('found2 ' );
230228
231229 $ collection ->expects ($ this ->at (1 ))
232230 ->method ('findOne ' )
233231 ->with (['v ' => 'found ' ])
234- ->will ( $ this -> returnValue ( 'foo ' ) );
232+ ->willReturn ( 'foo ' );
235233
236234 $ collection ->expects ($ this ->at (2 ))
237235 ->method ('findOne ' )
238236 ->with (['v ' => 'found2 ' ])
239- ->will ( $ this -> returnValue ( null ) );
237+ ->willReturn ( null );
240238
241239 $ this ->assertTrue ($ this ->configuration ->hasVersionMigrated ($ version1 ));
242240 $ this ->assertFalse ($ this ->configuration ->hasVersionMigrated ($ version2 ));
@@ -258,10 +256,10 @@ public function testGetUnavailableMigratedVersions()
258256 ->getMock ();
259257 $ configuration ->expects ($ this ->once ())
260258 ->method ('getMigratedVersions ' )
261- ->will ( $ this -> returnValue ( ['1 ' , '2 ' ]) );
259+ ->willReturn ( ['1 ' , '2 ' ]);
262260 $ configuration ->expects ($ this ->once ())
263261 ->method ('getAvailableVersions ' )
264- ->will ( $ this -> returnValue ( ['2 ' , '3 ' ]) );
262+ ->willReturn ( ['2 ' , '3 ' ]);
265263
266264 $ this ->assertEquals (['1 ' ], $ configuration ->getUnavailableMigratedVersions ());
267265 }
@@ -272,6 +270,74 @@ public function testValidate()
272270 self ::assertNull ($ this ->configuration ->validate ());
273271 }
274272
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+
275341 private function prepareValidConfiguration ()
276342 {
277343 $ directory = dirname (__DIR__ ) . '/Resources/Migrations/ ' ;
0 commit comments