Skip to content

Commit 643f590

Browse files
Merge branch '5.1' into 5.2
* 5.1: Use createMock() and use import instead of FQCN
2 parents 6b448da + 397a1df commit 643f590

File tree

7 files changed

+35
-30
lines changed

7 files changed

+35
-30
lines changed

Tests/LockFactoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class LockFactoryTest extends TestCase
2424
{
2525
public function testCreateLock()
2626
{
27-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
27+
$store = $this->createMock(PersistingStoreInterface::class);
2828
$store->expects($this->any())->method('exists')->willReturn(false);
2929

3030
$keys = [];
@@ -38,7 +38,7 @@ public function testCreateLock()
3838
}))
3939
->willReturn(true);
4040

41-
$logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
41+
$logger = $this->createMock(LoggerInterface::class);
4242
$factory = new LockFactory($store);
4343
$factory->setLogger($logger);
4444

Tests/LockTest.php

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Lock\BlockingSharedLockStoreInterface;
1717
use Symfony\Component\Lock\BlockingStoreInterface;
1818
use Symfony\Component\Lock\Exception\LockConflictedException;
19+
use Symfony\Component\Lock\Exception\LockReleasingException;
1920
use Symfony\Component\Lock\Key;
2021
use Symfony\Component\Lock\Lock;
2122
use Symfony\Component\Lock\PersistingStoreInterface;
@@ -30,7 +31,7 @@ class LockTest extends TestCase
3031
public function testAcquireNoBlocking()
3132
{
3233
$key = new Key(uniqid(__METHOD__, true));
33-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
34+
$store = $this->createMock(PersistingStoreInterface::class);
3435
$lock = new Lock($key, $store);
3536

3637
$store
@@ -46,7 +47,7 @@ public function testAcquireNoBlocking()
4647
public function testAcquireNoBlockingWithPersistingStoreInterface()
4748
{
4849
$key = new Key(uniqid(__METHOD__, true));
49-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
50+
$store = $this->createMock(PersistingStoreInterface::class);
5051
$lock = new Lock($key, $store);
5152

5253
$store
@@ -100,7 +101,7 @@ public function testAcquireBlockingRetryWithPersistingStoreInterface()
100101
public function testAcquireReturnsFalse()
101102
{
102103
$key = new Key(uniqid(__METHOD__, true));
103-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
104+
$store = $this->createMock(PersistingStoreInterface::class);
104105
$lock = new Lock($key, $store);
105106

106107
$store
@@ -117,7 +118,7 @@ public function testAcquireReturnsFalse()
117118
public function testAcquireReturnsFalseStoreInterface()
118119
{
119120
$key = new Key(uniqid(__METHOD__, true));
120-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
121+
$store = $this->createMock(PersistingStoreInterface::class);
121122
$lock = new Lock($key, $store);
122123

123124
$store
@@ -153,7 +154,7 @@ public function testAcquireBlockingWithBlockingStoreInterface()
153154
public function testAcquireSetsTtl()
154155
{
155156
$key = new Key(uniqid(__METHOD__, true));
156-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
157+
$store = $this->createMock(PersistingStoreInterface::class);
157158
$lock = new Lock($key, $store, 10);
158159

159160
$store
@@ -173,7 +174,7 @@ public function testAcquireSetsTtl()
173174
public function testRefresh()
174175
{
175176
$key = new Key(uniqid(__METHOD__, true));
176-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
177+
$store = $this->createMock(PersistingStoreInterface::class);
177178
$lock = new Lock($key, $store, 10);
178179

179180
$store
@@ -190,7 +191,7 @@ public function testRefresh()
190191
public function testRefreshCustom()
191192
{
192193
$key = new Key(uniqid(__METHOD__, true));
193-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
194+
$store = $this->createMock(PersistingStoreInterface::class);
194195
$lock = new Lock($key, $store, 10);
195196

196197
$store
@@ -207,7 +208,7 @@ public function testRefreshCustom()
207208
public function testIsAquired()
208209
{
209210
$key = new Key(uniqid(__METHOD__, true));
210-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
211+
$store = $this->createMock(PersistingStoreInterface::class);
211212
$lock = new Lock($key, $store, 10);
212213

213214
$store
@@ -221,7 +222,7 @@ public function testIsAquired()
221222
public function testRelease()
222223
{
223224
$key = new Key(uniqid(__METHOD__, true));
224-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
225+
$store = $this->createMock(PersistingStoreInterface::class);
225226
$lock = new Lock($key, $store, 10);
226227

227228
$store
@@ -241,7 +242,7 @@ public function testRelease()
241242
public function testReleaseStoreInterface()
242243
{
243244
$key = new Key(uniqid(__METHOD__, true));
244-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
245+
$store = $this->createMock(PersistingStoreInterface::class);
245246
$lock = new Lock($key, $store, 10);
246247

247248
$store
@@ -298,9 +299,9 @@ public function testNoAutoReleaseWhenNotConfigured()
298299

299300
public function testReleaseThrowsExceptionWhenDeletionFail()
300301
{
301-
$this->expectException(\Symfony\Component\Lock\Exception\LockReleasingException::class);
302+
$this->expectException(LockReleasingException::class);
302303
$key = new Key(uniqid(__METHOD__, true));
303-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
304+
$store = $this->createMock(PersistingStoreInterface::class);
304305
$lock = new Lock($key, $store, 10);
305306

306307
$store
@@ -319,9 +320,9 @@ public function testReleaseThrowsExceptionWhenDeletionFail()
319320

320321
public function testReleaseThrowsExceptionIfNotWellDeleted()
321322
{
322-
$this->expectException(\Symfony\Component\Lock\Exception\LockReleasingException::class);
323+
$this->expectException(LockReleasingException::class);
323324
$key = new Key(uniqid(__METHOD__, true));
324-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
325+
$store = $this->createMock(PersistingStoreInterface::class);
325326
$lock = new Lock($key, $store, 10);
326327

327328
$store
@@ -340,10 +341,10 @@ public function testReleaseThrowsExceptionIfNotWellDeleted()
340341

341342
public function testReleaseThrowsAndLog()
342343
{
343-
$this->expectException(\Symfony\Component\Lock\Exception\LockReleasingException::class);
344+
$this->expectException(LockReleasingException::class);
344345
$key = new Key(uniqid(__METHOD__, true));
345-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
346-
$logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
346+
$store = $this->createMock(PersistingStoreInterface::class);
347+
$logger = $this->createMock(LoggerInterface::class);
347348
$lock = new Lock($key, $store, 10, true);
348349
$lock->setLogger($logger);
349350

@@ -371,7 +372,7 @@ public function testReleaseThrowsAndLog()
371372
public function testExpiration($ttls, $expected)
372373
{
373374
$key = new Key(uniqid(__METHOD__, true));
374-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
375+
$store = $this->createMock(PersistingStoreInterface::class);
375376
$lock = new Lock($key, $store, 10);
376377

377378
foreach ($ttls as $ttl) {
@@ -390,7 +391,7 @@ public function testExpiration($ttls, $expected)
390391
public function testExpirationStoreInterface($ttls, $expected)
391392
{
392393
$key = new Key(uniqid(__METHOD__, true));
393-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
394+
$store = $this->createMock(PersistingStoreInterface::class);
394395
$lock = new Lock($key, $store, 10);
395396

396397
foreach ($ttls as $ttl) {

Tests/Store/CombinedStoreTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function getStore(): PersistingStoreInterface
6464

6565
protected function setUp(): void
6666
{
67-
$this->strategy = $this->getMockBuilder(StrategyInterface::class)->getMock();
67+
$this->strategy = $this->createMock(StrategyInterface::class);
6868
$this->store1 = $this->createMock(BlockingStoreInterface::class);
6969
$this->store2 = $this->createMock(BlockingStoreInterface::class);
7070

@@ -266,8 +266,8 @@ public function testputOffExpirationAbortWhenStrategyCantBeMet()
266266

267267
public function testPutOffExpirationIgnoreNonExpiringStorage()
268268
{
269-
$store1 = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
270-
$store2 = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
269+
$store1 = $this->createMock(PersistingStoreInterface::class);
270+
$store2 = $this->createMock(PersistingStoreInterface::class);
271271

272272
$store = new CombinedStore([$store1, $store2], $this->strategy);
273273

Tests/Store/FlockStoreTest.php

Lines changed: 3 additions & 2 deletions
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\Exception\InvalidArgumentException;
1415
use Symfony\Component\Lock\Key;
1516
use Symfony\Component\Lock\PersistingStoreInterface;
1617
use Symfony\Component\Lock\Store\FlockStore;
@@ -34,7 +35,7 @@ protected function getStore(): PersistingStoreInterface
3435

3536
public function testConstructWhenRepositoryDoesNotExist()
3637
{
37-
$this->expectException(\Symfony\Component\Lock\Exception\InvalidArgumentException::class);
38+
$this->expectException(InvalidArgumentException::class);
3839
$this->expectExceptionMessage('The directory "/a/b/c/d/e" is not writable.');
3940
if (!getenv('USER') || 'root' === getenv('USER')) {
4041
$this->markTestSkipped('This test will fail if run under superuser');
@@ -45,7 +46,7 @@ public function testConstructWhenRepositoryDoesNotExist()
4546

4647
public function testConstructWhenRepositoryIsNotWriteable()
4748
{
48-
$this->expectException(\Symfony\Component\Lock\Exception\InvalidArgumentException::class);
49+
$this->expectException(InvalidArgumentException::class);
4950
$this->expectExceptionMessage('The directory "/" is not writable.');
5051
if (!getenv('USER') || 'root' === getenv('USER')) {
5152
$this->markTestSkipped('This test will fail if run under superuser');

Tests/Store/MemcachedStoreTest.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\Exception\InvalidTtlException;
1415
use Symfony\Component\Lock\Key;
1516
use Symfony\Component\Lock\PersistingStoreInterface;
1617
use Symfony\Component\Lock\Store\MemcachedStore;
@@ -63,7 +64,7 @@ public function testAbortAfterExpiration()
6364

6465
public function testInvalidTtl()
6566
{
66-
$this->expectException(\Symfony\Component\Lock\Exception\InvalidTtlException::class);
67+
$this->expectException(InvalidTtlException::class);
6768
$store = $this->getStore();
6869
$store->putOffExpiration(new Key('toto'), 0.1);
6970
}

Tests/Store/PdoStoreTest.php

Lines changed: 3 additions & 2 deletions
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\Exception\InvalidTtlException;
1415
use Symfony\Component\Lock\Key;
1516
use Symfony\Component\Lock\PersistingStoreInterface;
1617
use Symfony\Component\Lock\Store\PdoStore;
@@ -62,14 +63,14 @@ public function testAbortAfterExpiration()
6263

6364
public function testInvalidTtl()
6465
{
65-
$this->expectException(\Symfony\Component\Lock\Exception\InvalidTtlException::class);
66+
$this->expectException(InvalidTtlException::class);
6667
$store = $this->getStore();
6768
$store->putOffExpiration(new Key('toto'), 0.1);
6869
}
6970

7071
public function testInvalidTtlConstruct()
7172
{
72-
$this->expectException(\Symfony\Component\Lock\Exception\InvalidTtlException::class);
73+
$this->expectException(InvalidTtlException::class);
7374

7475
return new PdoStore('sqlite:'.self::$dbFile, [], 0.1, 0.1);
7576
}

Tests/Store/RedisStoreTest.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\Exception\InvalidTtlException;
1415
use Symfony\Component\Lock\Store\RedisStore;
1516

1617
/**
@@ -45,7 +46,7 @@ protected function getRedisConnection(): object
4546

4647
public function testInvalidTtl()
4748
{
48-
$this->expectException(\Symfony\Component\Lock\Exception\InvalidTtlException::class);
49+
$this->expectException(InvalidTtlException::class);
4950
new RedisStore($this->getRedisConnection(), -1);
5051
}
5152
}

0 commit comments

Comments
 (0)