@@ -41,7 +41,7 @@ protected function setUp()
41
41
'data_field ' => 'data ' ,
42
42
'time_field ' => 'time ' ,
43
43
'database ' => 'sf2-test ' ,
44
- 'collection ' => 'session-test '
44
+ 'collection ' => 'session-test ' ,
45
45
);
46
46
47
47
$ this ->storage = new MongoDbSessionHandler ($ this ->mongo , $ this ->options );
@@ -100,6 +100,45 @@ public function testWrite()
100
100
$ that ->assertInstanceOf ('MongoDate ' , $ data [$ this ->options ['time_field ' ]]);
101
101
}
102
102
103
+ public function testWriteWhenUsingExpiresField ()
104
+ {
105
+ $ this ->options = array (
106
+ 'id_field ' => '_id ' ,
107
+ 'data_field ' => 'data ' ,
108
+ 'time_field ' => 'time ' ,
109
+ 'database ' => 'sf2-test ' ,
110
+ 'collection ' => 'session-test ' ,
111
+ 'expiry_field ' => 'expiresAt '
112
+ );
113
+
114
+ $ this ->storage = new MongoDbSessionHandler ($ this ->mongo , $ this ->options );
115
+
116
+ $ collection = $ this ->createMongoCollectionMock ();
117
+
118
+ $ this ->mongo ->expects ($ this ->once ())
119
+ ->method ('selectCollection ' )
120
+ ->with ($ this ->options ['database ' ], $ this ->options ['collection ' ])
121
+ ->will ($ this ->returnValue ($ collection ));
122
+
123
+ $ that = $ this ;
124
+ $ data = array ();
125
+
126
+ $ collection ->expects ($ this ->once ())
127
+ ->method ('update ' )
128
+ ->will ($ this ->returnCallback (function ($ criteria , $ updateData , $ options ) use ($ that , &$ data ) {
129
+ $ that ->assertEquals (array ($ that ->options ['id_field ' ] => 'foo ' ), $ criteria );
130
+ $ that ->assertEquals (array ('upsert ' => true , 'multiple ' => false ), $ options );
131
+
132
+ $ data = $ updateData ['$set ' ];
133
+ }));
134
+
135
+ $ this ->assertTrue ($ this ->storage ->write ('foo ' , 'bar ' ));
136
+
137
+ $ this ->assertEquals ('bar ' , $ data [$ this ->options ['data_field ' ]]->bin );
138
+ $ that ->assertInstanceOf ('MongoDate ' , $ data [$ this ->options ['time_field ' ]]);
139
+ $ that ->assertInstanceOf ('MongoDate ' , $ data [$ this ->options ['expiry_field ' ]]);
140
+ }
141
+
103
142
public function testReplaceSessionData ()
104
143
{
105
144
$ collection = $ this ->createMongoCollectionMock ();
@@ -154,10 +193,36 @@ public function testGc()
154
193
->method ('remove ' )
155
194
->will ($ this ->returnCallback (function ($ criteria ) use ($ that ) {
156
195
$ that ->assertInstanceOf ('MongoDate ' , $ criteria [$ that ->options ['time_field ' ]]['$lt ' ]);
157
- $ that ->assertGreaterThanOrEqual (time () - - 1 , $ criteria [$ that ->options ['time_field ' ]]['$lt ' ]->sec );
196
+ $ that ->assertGreaterThanOrEqual (time () - 1 , $ criteria [$ that ->options ['time_field ' ]]['$lt ' ]->sec );
158
197
}));
159
198
160
- $ this ->assertTrue ($ this ->storage ->gc (-1 ));
199
+ $ this ->assertTrue ($ this ->storage ->gc (1 ));
200
+ }
201
+
202
+ public function testGcWhenUsingExpiresField ()
203
+ {
204
+ $ this ->options = array (
205
+ 'id_field ' => '_id ' ,
206
+ 'data_field ' => 'data ' ,
207
+ 'time_field ' => 'time ' ,
208
+ 'database ' => 'sf2-test ' ,
209
+ 'collection ' => 'session-test ' ,
210
+ 'expiry_field ' => 'expiresAt '
211
+ );
212
+
213
+ $ this ->storage = new MongoDbSessionHandler ($ this ->mongo , $ this ->options );
214
+
215
+ $ collection = $ this ->createMongoCollectionMock ();
216
+
217
+ $ this ->mongo ->expects ($ this ->never ())
218
+ ->method ('selectCollection ' );
219
+
220
+ $ that = $ this ;
221
+
222
+ $ collection ->expects ($ this ->never ())
223
+ ->method ('remove ' );
224
+
225
+ $ this ->assertTrue ($ this ->storage ->gc (1 ));
161
226
}
162
227
163
228
public function testGetConnection ()
0 commit comments