8000 Ensure compatibility with mongodb v2 · symfony/symfony@77588b8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 77588b8

Browse files
committed
Ensure compatibility with mongodb v2
1 parent ebd2270 commit 77588b8

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ public function testWrite()
133133
$this->assertInstanceOf(\MongoDB\BSON\UTCDateTime::class, $data[$this->options['time_field']]);
134134
$this->assertInstanceOf(\MongoDB\BSON\UTCDateTime::class, $data[$this->options['expiry_field']]);
135135
$this->assertGreaterThanOrEqual($expectedExpiry, round((string) $data[$this->options['expiry_field']] / 1000));
136+
137+
return $this->createMock(\MongoDB\UpdateResult::class);
136138
});
137139

138140
$this->assertTrue($this->storage->write('foo', 'bar'));
@@ -153,6 +155,8 @@ public function testReplaceSessionData()
153155
->method('updateOne')
154156
->willReturnCallback(function ($criteria, $updateData, $options) use (&$data) {
155157
$data = $updateData;
158+
159+
return $this->createMock(\MongoDB\UpdateResult::class);
156160
});
157161

158162
$this->storage->write('foo', 'bar');

src/Symfony/Component/Lock/Store/MongoDbStore.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use MongoDB\BSON\UTCDateTime;
1515
use MongoDB\Client;
1616
use MongoDB\Collection;
17-
use MongoDB\Driver\Exception\WriteException;
17+
use MongoDB\Driver\Exception\BulkWriteException;
1818
use MongoDB\Driver\ReadPreference;
1919
use MongoDB\Exception\DriverRuntimeException;
2020
use MongoDB\Exception\InvalidArgumentException as MongoInvalidArgumentException;
@@ -209,7 +209,7 @@ public function save(Key $key)
209209

210210
try {
211211
$this->upsert($key, $this->initialTtl);
212-
} catch (WriteException $e) {
212+
} catch (BulkWriteException $e) {
213213
if ($this->isDuplicateKeyException($e)) {
214214
throw new LockConflictedException('Lock was acquired by someone else.', 0, $e);
215215
}
@@ -235,7 +235,7 @@ public function putOffExpiration(Key $key, float $ttl)
235235

236236
try {
237237
$this->upsert($key, $ttl);
238-
} catch (WriteException $e) {
238+
} catch (BulkWriteException $e) {
239239
if ($this->isDuplicateKeyException($e)) {
240240
throw new LockConflictedException('Failed to put off the expiration of the lock.', 0, $e);
241241
}
@@ -268,7 +268,7 @@ public function exists(Key $key): bool
268268
'$gt' => $this->createMongoDateTime(microtime(true)),
269269
],
270270
], [
271-
'readPreference' => new ReadPreference(\defined(ReadPreference::PRIMARY) ? ReadPreference::PRIMARY : ReadPreference::RP_PRIMARY),
271+
'readPreference' => new ReadPreference(\defined(ReadPreference::class.'::PRIMARY') ? ReadPreference::PRIMARY : ReadPreference::RP_PRIMARY),
272272
]);
273273
}
274274

@@ -309,7 +309,7 @@ private function upsert(Key $key, float $ttl)
309309
);
310310
}
311311

312-
private function isDuplicateKeyException(WriteException $e): bool
312+
private function isDuplicateKeyException(BulkWriteException $e): bool
313313
{
314314
$code = $e->getCode();
315315

@@ -345,7 +345,7 @@ private function getCollection(): Collection
345345
*/
346346
private function createMongoDateTime(float $seconds): UTCDateTime
347347
{
348-
return new UTCDateTime($seconds * 1000);
348+
return new UTCDateTime(intval($seconds * 1000));
349349
}
350350

351351
/**

0 commit comments

Comments
 (0)
0