Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bae2782

Browse files
Merge branch '4.4' into 5.1
* 4.4: Fix EncoderInterface::encode() return type [Lock] Prevent store exception break combined store
2 parents aa0d2c8 + c052542 commit bae2782

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,14 @@ public function exists(Key $key)
158158
$storesCount = \count($this->stores);
159159

160160
foreach ($this->stores as $store) {
161-
if ($store->exists($key)) {
162-
++$successCount;
163-
} else {
161+
try {
162+
if ($store->exists($key)) {
163+
++$successCount;
164+
} else {
165+
++$failureCount;
166+
}
167+
} catch (\Exception $e) {
168+
$this->logger->debug('One store failed to check the "{resource}" lock.', ['resource' => $key, 'store' => $store, 'exception' => $e]);
164169
++$failureCount;
165170
}
166171

src/Symfony/Component/Lock/Tests/Store/CombinedStoreTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,4 +351,29 @@ public function testDeleteDontStopOnFailure()
351351

352352
$this->store->delete($key);
353353
}
354+
355+
public function testExistsDontStopOnFailure()
356+
{
357+
$key = new Key(uniqid(__METHOD__, true));
358+
359+
$this->strategy
360+
->expects($this->any())
361+
->method('canBeMet')
362+
->willReturn(true);
363+
$this->strategy
364+
->expects($this->any())
365+
->method('isMet')
366+
->willReturn(false);
367+
$this->store1
368+
->expects($this->once())
369+
->method('exists')
370+
->willThrowException(new \Exception());
371+
$this->store2
372+
->expects($this->once())
373+
->method('exists')
374+
->with($key)
375+
->willReturn(false);
376+
377+
$this->assertFalse($this->store->exists($key));
378+
}
354379
}

src/Symfony/Component/Serializer/Encoder/EncoderInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ interface EncoderInterface
2525
* @param string $format Format name
2626
* @param array $context Options that normalizers/encoders have access to
2727
*
28-
* @return string|int|float|bool
28+
* @return string
2929
*
3030
* @throws UnexpectedValueException
3131
*/

src/Symfony/Component/Serializer/Tests/Encoder/ChainEncoderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ public function testSupportsEncoding()
6767
public function testEncode()
6868
{
6969
$this->encoder1->expects($this->never())->method('encode');
70-
$this->encoder2->expects($this->once())->method('encode');
70+
$this->encoder2->expects($this->once())->method('encode')->willReturn('foo:123');
7171

72-
$this->chainEncoder->encode(['foo' => 123], self::FORMAT_2);
72+
$this->assertSame('foo:123', $this->chainEncoder->encode(['foo' => 123], self::FORMAT_2));
7373
}
7474

7575
public function testEncodeUnsupportedFormat()

0 commit comments

Comments
 (0)