Skip to content

Commit 243c3e6

Browse files
committed
Fix Psalm, add unit tests
1 parent 1c64234 commit 243c3e6

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

psalm.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
55
xmlns="https://getpsalm.org/schema/config"
66
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
7+
findUnusedBaselineEntry="true"
8+
findUnusedCode="false"
79
>
810
<projectFiles>
911
<directory name="src"/>

src/RoadRunnerStore.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Symfony\Component\Lock\BlockingStoreInterface;
1010
use Symfony\Component\Lock\Exception\LockAcquiringException;
1111
use Symfony\Component\Lock\Exception\LockConflictedException;
12-
use Symfony\Component\Lock\Exception\LockReleasingException;
1312
use Symfony\Component\Lock\Key;
1413
use Symfony\Component\Lock\SharedLockStoreInterface;
1514
use Symfony\Component\Lock\Store\ExpiringStoreTrait;
@@ -122,8 +121,8 @@ public function waitAndSave(Key $key): void
122121
$status = $this->lock->lock($resource, $lockId, $this->initialTtl, $this->initialWaitTtl);
123122

124123
$key->setState(__CLASS__, $lockId);
125-
if (!$status) {
126-
throw new LockConflictedException();
124+
if ($status === false) {
125+
throw new LockConflictedException('RoadRunner. Failed to make lock');
127126
}
128127

129128
$this->checkNotExpired($key);

tests/RoadRunnerStoreTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,33 @@ public function testDeleteFail(): void
161161
$key->setState(RoadRunnerStore::class, 'lock-id');
162162
$store->delete($key);
163163
}
164+
165+
public function testWaitAndSaveSuccess(): void
166+
{
167+
$this->rrLock->expects($this->once())
168+
->method('lock')
169+
->with('resource-name', 'random-id', 300, 60)
170+
->willReturn('lock-id');
171+
172+
$store = new RoadRunnerStore($this->rrLock, $this->tokens);
173+
$key = new Key('resource-name');
174+
$store->waitAndSave($key);
175+
176+
$this->assertTrue($key->hasState(RoadRunnerStore::class));
177+
$this->assertSame('random-id', $key->getState(RoadRunnerStore::class));
178+
}
179+
180+
public function testWaitAndSaveFail(): void
181+
{
182+
$this->expectException(LockConflictedException::class);
183+
$this->expectExceptionMessage('RoadRunner. Failed to make lock');
184+
185+
$this->rrLock->expects($this->once())
186+
->method('lock')
187+
->with('resource-name', 'random-id', 300, 60)
188+
->willReturn(false);
189+
190+
$store = new RoadRunnerStore($this->rrLock, $this->tokens);
191+
$store->waitAndSave(new Key('resource-name'));
192+
}
164193
}

0 commit comments

Comments
 (0)