Skip to content

Commit b2a27e7

Browse files
Add return types to tests and final|internal|private methods
1 parent b97150a commit b2a27e7

13 files changed

+57
-26
lines changed

Key.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,12 @@ public function reduceLifetime($ttl)
7474
*
7575
* @return float|null Remaining lifetime in seconds. Null when the key won't expire.
7676
*/
77-
public function getRemainingLifetime()
77+
public function getRemainingLifetime(): ?float
7878
{
7979
return null === $this->expiringTime ? null : $this->expiringTime - microtime(true);
8080
}
8181

82-
/**
83-
* @return bool
84-
*/
85-
public function isExpired()
82+
public function isExpired(): bool
8683
{
8784
return null !== $this->expiringTime && $this->expiringTime <= microtime(true);
8885
}

Lock.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function __destruct()
6565
/**
6666
* {@inheritdoc}
6767
*/
68-
public function acquire($blocking = false)
68+
public function acquire($blocking = false): bool
6969
{
7070
try {
7171
if ($blocking) {
@@ -149,7 +149,7 @@ public function refresh($ttl = null)
149149
/**
150150
* {@inheritdoc}
151151
*/
152-
public function isAcquired()
152+
public function isAcquired(): bool
153153
{
154154
return $this->dirty = $this->store->exists($this->key);
155155
}
@@ -181,15 +181,15 @@ public function release()
181181
/**
182182
* {@inheritdoc}
183183
*/
184-
public function isExpired()
184+
public function isExpired(): bool
185185
{
186186
return $this->key->isExpired();
187187
}
188188

189189
/**
190190
* {@inheritdoc}
191191
*/
192-
public function getRemainingLifetime()
192+
public function getRemainingLifetime(): ?float
193193
{
194194
return $this->key->getRemainingLifetime();
195195
}

Tests/LockTest.php

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ public function testAcquireNoBlocking()
3434
$store
3535
->expects($this->once())
3636
->method('save');
37+
$store
38+
->method('exists')
39+
->willReturnOnConsecutiveCalls(true, false);
3740

3841
$this->assertTrue($lock->acquire(false));
3942
}
@@ -47,6 +50,9 @@ public function testAcquireNoBlockingStoreInterface()
4750
$store
4851
->expects($this->once())
4952
->method('save');
53+
$store
54+
->method('exists')
55+
->willReturnOnConsecutiveCalls(true, false);
5056

5157
$this->assertTrue($lock->acquire(false));
5258
}
@@ -63,6 +69,9 @@ public function testPassingOldStoreInterface()
6369
$store
6470
->expects($this->once())
6571
->method('save');
72+
$store
73+
->method('exists')
74+
->willReturnOnConsecutiveCalls(true, false);
6675

6776
$this->assertTrue($lock->acquire(false));
6877
}
@@ -77,6 +86,9 @@ public function testAcquireReturnsFalse()
7786
->expects($this->once())
7887
->method('save')
7988
->willThrowException(new LockConflictedException());
89+
$store
90+
->method('exists')
91+
->willReturnOnConsecutiveCalls(true, false);
8092

8193
$this->assertFalse($lock->acquire(false));
8294
}
@@ -91,6 +103,9 @@ public function testAcquireReturnsFalseStoreInterface()
91103
->expects($this->once())
92104
->method('save')
93105
->willThrowException(new LockConflictedException());
106+
$store
107+
->method('exists')
108+
->willReturnOnConsecutiveCalls(true, false);
94109

95110
$this->assertFalse($lock->acquire(false));
96111
}
@@ -107,6 +122,9 @@ public function testAcquireBlocking()
107122
$store
108123
->expects($this->once())
109124
->method('waitAndSave');
125+
$store
126+
->method('exists')
127+
->willReturnOnConsecutiveCalls(true, false);
110128

111129
$this->assertTrue($lock->acquire(true));
112130
}
@@ -124,6 +142,9 @@ public function testAcquireSetsTtl()
124142
->expects($this->once())
125143
->method('putOffExpiration')
126144
->with($key, 10);
145+
$store
146+
->method('exists')
147+
->willReturnOnConsecutiveCalls(true, false);
127148

128149
$lock->acquire();
129150
}
@@ -138,6 +159,9 @@ public function testRefresh()
138159
->expects($this->once())
139160
->method('putOffExpiration')
140161
->with($key, 10);
162+
$store
163+
->method('exists')
164+
->willReturnOnConsecutiveCalls(true, false);
141165

142166
$lock->refresh();
143167
}
@@ -152,6 +176,9 @@ public function testRefreshCustom()
152176
->expects($this->once())
153177
->method('putOffExpiration')
154178
->with($key, 20);
179+
$store
180+
->method('exists')
181+
->willReturnOnConsecutiveCalls(true, false);
155182

156183
$lock->refresh(20);
157184
}
@@ -163,10 +190,9 @@ public function testIsAquired()
163190
$lock = new Lock($key, $store, 10);
164191

165192
$store
166-
->expects($this->any())
167193
->method('exists')
168194
->with($key)
169-
->will($this->onConsecutiveCalls(true, false));
195+
->willReturnOnConsecutiveCalls(true, false);
170196

171197
$this->assertTrue($lock->isAcquired());
172198
}
@@ -219,7 +245,7 @@ public function testReleaseOnDestruction()
219245

220246
$store
221247
->method('exists')
222-
->willReturnOnConsecutiveCalls([true, false])
248+
->willReturnOnConsecutiveCalls(true, false)
223249
;
224250
$store
225251
->expects($this->once())
@@ -238,7 +264,7 @@ public function testNoAutoReleaseWhenNotConfigured()
238264

239265
$store
240266
->method('exists')
241-
->willReturnOnConsecutiveCalls([true, false])
267+
->willReturnOnConsecutiveCalls(true, false)
242268
;
243269
$store
244270
->expects($this->never())

Tests/Store/AbstractRedisStoreTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Lock\Tests\Store;
1313

14+
use Symfony\Component\Lock\PersistingStoreInterface;
1415
use Symfony\Component\Lock\Store\RedisStore;
1516

1617
/**
@@ -38,7 +39,7 @@ abstract protected function getRedisConnection();
3839
/**
3940
* {@inheritdoc}
4041
*/
41-
public function getStore()
42+
public function getStore(): PersistingStoreInterface
4243
{
4344
return new RedisStore($this->getRedisConnection());
4445
}

Tests/Store/AbstractStoreTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@
2121
*/
2222
abstract class AbstractStoreTest extends TestCase
2323
{
24-
/**
25-
* @return PersistingStoreInterface
26-
*/
27-
abstract protected function getStore();
24+
abstract protected function getStore(): PersistingStoreInterface;
2825

2926
public function testSave()
3027
{

Tests/Store/CombinedStoreTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protected function getClockDelay()
3939
/**
4040
* {@inheritdoc}
4141
*/
42-
public function getStore()
42+
public function getStore(): PersistingStoreInterface
4343
{
4444
$redis = new \Predis\Client('tcp://'.getenv('REDIS_HOST').':6379');
4545
try {

Tests/Store/FlockStoreTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Lock\Tests\Store;
1313

1414
use Symfony\Component\Lock\Key;
15+
use Symfony\Component\Lock\PersistingStoreInterface;
1516
use Symfony\Component\Lock\Store\FlockStore;
1617

1718
/**
@@ -24,7 +25,7 @@ class FlockStoreTest extends AbstractStoreTest
2425
/**
2526
* {@inheritdoc}
2627
*/
27-
protected function getStore()
28+
protected function getStore(): PersistingStoreInterface
2829
{
2930
return new FlockStore();
3031
}

Tests/Store/MemcachedStoreTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Lock\Tests\Store;
1313

1414
use Symfony\Component\Lock\Key;
15+
use Symfony\Component\Lock\PersistingStoreInterface;
1516
use Symfony\Component\Lock\Store\MemcachedStore;
1617

1718
/**
@@ -46,7 +47,7 @@ protected function getClockDelay()
4647
/**
4748
* {@inheritdoc}
4849
*/
49-
public function getStore()
50+
public function getStore(): PersistingStoreInterface
5051
{
5152
$memcached = new \Memcached();
5253
$memcached->addServer(getenv('MEMCACHED_HOST'), 11211);

Tests/Store/PdoDbalStoreTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Lock\Tests\Store;
1313

1414
use Doctrine\DBAL\DriverManager;
15+
use Symfony\Component\Lock\PersistingStoreInterface;
1516
use Symfony\Component\Lock\Store\PdoStore;
1617

1718
/**
@@ -49,7 +50,7 @@ protected function getClockDelay()
4950
/**
5051
* {@inheritdoc}
5152
*/
52-
public function getStore()
53+
public function getStore(): PersistingStoreInterface
5354
{
5455
return new PdoStore(DriverManager::getConnection(['driver' => 'pdo_sqlite', 'path' => self::$dbFile]));
5556
}

Tests/Store/PdoStoreTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Lock\Tests\Store;
1313

1414
use Symfony\Component\Lock\Key;
15+
use Symfony\Component\Lock\PersistingStoreInterface;
1516
use Symfony\Component\Lock\Store\PdoStore;
1617

1718
/**
@@ -49,7 +50,7 @@ protected function getClockDelay()
4950
/**
5051
* {@inheritdoc}
5152
*/
52-
public function getStore()
53+
public function getStore(): PersistingStoreInterface
5354
{
5455
return new PdoStore('sqlite:'.self::$dbFile);
5556
}

0 commit comments

Comments
 (0)