Skip to content

Commit 26a33b5

Browse files
committed
tests
1 parent d337af4 commit 26a33b5

File tree

3 files changed

+94
-2
lines changed

3 files changed

+94
-2
lines changed

src/Bridge/Symfony/Seal/SymfonyLockSeal.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,14 @@ public function refresh(SealToken $token, ?float $ttlInSeconds = null): SealToke
5858
throw new LeaseExpiredException((string) $token, 'Invalid token type');
5959
}
6060

61+
$effectiveTtl = $ttlInSeconds ?? $this->ttlInSeconds;
62+
6163
$lock = $this->factory->createLockFromKey(
6264
$token->getKey(),
63-
$ttlInSeconds ?? $this->ttlInSeconds
65+
$effectiveTtl
6466
);
6567

6668
try {
67-
$effectiveTtl = $ttlInSeconds ?? $this->ttlInSeconds;
6869
$lock->refresh($effectiveTtl);
6970

7071
return $token;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Clegginabox\Airlock\Tests\Unit\Bridge\Symfony\Seal;
6+
7+
use Clegginabox\Airlock\Bridge\Symfony\Seal\SymfonyLockSeal;
8+
use Clegginabox\Airlock\Bridge\Symfony\Seal\SymfonyLockToken;
9+
use PHPUnit\Framework\TestCase;
10+
use Symfony\Component\Lock\LockFactory;
11+
use Symfony\Component\Lock\Store\FlockStore;
12+
13+
class SymfonyLockSealTest extends TestCase
14+
{
15+
private SymfonyLockSeal $seal;
16+
17+
protected function setUp(): void
18+
{
19+
$store = new FlockStore();
20+
21+
$this->seal = new SymfonyLockSeal(
22+
new LockFactory($store),
23+
'lock-seal-test',
24+
300,
25+
false
26+
);
27+
}
28+
29+
public function testItAcquiresLock(): void
30+
{
31+
$token = $this->seal->tryAcquire();
32+
33+
$this->assertInstanceof(SymfonyLockToken::class, $token);
34+
$this->assertTrue($this->seal->isAcquired($token));
35+
}
36+
37+
public function testItReleasesLock(): void
38+
{
39+
$token = $this->seal->tryAcquire();
40+
$this->assertInstanceof(SymfonyLockToken::class, $token);
41+
42+
$this->seal->release($token);
43+
}
44+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Clegginabox\Airlock\Tests\Unit\Bridge\Symfony\Seal;
6+
7+
use Clegginabox\Airlock\Bridge\Symfony\Seal\SymfonyLockToken;
8+
use PHPUnit\Framework\TestCase;
9+
use Symfony\Component\Lock\Key;
10+
11+
class SymfonyLockTokenTest extends TestCase
12+
{
13+
public function testGetKey(): void
14+
{
15+
$key = new Key('test-resource');
16+
$token = new SymfonyLockToken($key);
17+
18+
$this->assertSame($key, $token->getKey());
19+
}
20+
21+
public function testGetResource(): void
22+
{
23+
$key = new Key('test-resource');
24+
$token = new SymfonyLockToken($key);
25+
26+
$this->assertSame($key->__toString(), $token->getResource());
27+
}
28+
29+
public function testGetId(): void
30+
{
31+
$key = new Key('test-resource');
32+
$token = new SymfonyLockToken($key);
33+
34+
$this->assertSame(
35+
hash('xxh128', serialize($key)),
36+
$token->getId()
37+
);
38+
}
39+
40+
public function testToString(): void
41+
{
42+
$key = new Key('test-resource');
43+
$token = new SymfonyLockToken($key);
44+
45+
$this->assertSame($token->__toString(), serialize($key));
46+
}
47+
}

0 commit comments

Comments
 (0)